From aafc6fad7d80883a2b92936bf27db15461849afc Mon Sep 17 00:00:00 2001 From: David Bolack Date: Tue, 14 Jan 2025 21:40:15 -0600 Subject: [PATCH 1/3] Implement suggested fix for 3488 Per issue --- shared/naturalcrit/markdown.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 852243d81..76938c7e0 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -1,3 +1,4 @@ +/* eslint-disable max-depth */ /* eslint-disable max-lines */ import _ from 'lodash'; import { Parser as MathParser } from 'expr-eval'; @@ -680,7 +681,7 @@ function MarkedVariables() { } if(match[8]) { // Inline Definition const label = match[10] ? match[10].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space - let content = match[11] ? match[11].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space + let content = match[11] ? match[11] : null; // Trim edge spaces and shorten blocks of whitespace to 1 space // In case of nested (), find the correct matching end ) let level = 0; @@ -696,10 +697,8 @@ function MarkedVariables() { break; } } - if(i > -1) { - combinedRegex.lastIndex = combinedRegex.lastIndex - (content.length - i); - content = content.slice(0, i).trim().replace(/\s+/g, ' '); - } + combinedRegex.lastIndex = combinedRegex.lastIndex - (content.length - i); + content = content.slice(0, i).trim().replace(/\s+/g, ' '); varsQueue.push( { type : 'varDefBlock', From d4f6c329b8064350a654b90094c5c483c0299b7a Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 15 Jan 2025 17:36:18 -0600 Subject: [PATCH 2/3] Add a test! --- shared/naturalcrit/markdown.js | 2 +- tests/markdown/variables.test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 76938c7e0..ffd2395fa 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -681,7 +681,7 @@ function MarkedVariables() { } if(match[8]) { // Inline Definition const label = match[10] ? match[10].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space - let content = match[11] ? match[11] : null; // Trim edge spaces and shorten blocks of whitespace to 1 space + let content = match[11] || null; // In case of nested (), find the correct matching end ) let level = 0; diff --git a/tests/markdown/variables.test.js b/tests/markdown/variables.test.js index be16e8a22..9a02d15eb 100644 --- a/tests/markdown/variables.test.js +++ b/tests/markdown/variables.test.js @@ -402,4 +402,10 @@ describe('Variable names that are subsets of other names', ()=>{ const rendered = Markdown.render(source).trimReturns(); expect(rendered).toBe('

14

'); }); +}); + +describe('Don\'t Eat all the parentheticals!', ()=>{ + const source='\n| title 1 | title 2 | title 3 | title 4|\n|-----------|---------|---------|--------|\n|[foo](bar) | Ipsum | ) | ) |\n'; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered).toBe('
title 1title 2title 3title 4
fooIpsum))
'); }); \ No newline at end of file From 5dbb5499c6fe8f0f6c9971e13d4c07820c5e0e29 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Fri, 17 Jan 2025 10:02:32 -0600 Subject: [PATCH 3/3] fix test --- tests/markdown/variables.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/markdown/variables.test.js b/tests/markdown/variables.test.js index 9a02d15eb..41259da7e 100644 --- a/tests/markdown/variables.test.js +++ b/tests/markdown/variables.test.js @@ -404,8 +404,10 @@ describe('Variable names that are subsets of other names', ()=>{ }); }); -describe('Don\'t Eat all the parentheticals!', ()=>{ - const source='\n| title 1 | title 2 | title 3 | title 4|\n|-----------|---------|---------|--------|\n|[foo](bar) | Ipsum | ) | ) |\n'; - const rendered = Markdown.render(source).trimReturns(); - expect(rendered).toBe('
title 1title 2title 3title 4
fooIpsum))
'); +describe('Regression Tests', ()=>{ + it('Don\'t Eat all the parentheticals!', function() { + const source='\n| title 1 | title 2 | title 3 | title 4|\n|-----------|---------|---------|--------|\n|[foo](bar) | Ipsum | ) | ) |\n'; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered).toBe('
title 1title 2title 3title 4
fooIpsum))
'); + }); }); \ No newline at end of file