From aee45c3daed7c1c8c6bf31731f28c429eeb1669c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 2 Feb 2024 15:03:50 -0700 Subject: [PATCH] Fix title-related backtracking with empty string Fixes #281 --- lib/inlines.js | 7 +++---- test/regression.txt | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/inlines.js b/lib/inlines.js index dd30bd4f..1ecf8eef 100644 --- a/lib/inlines.js +++ b/lib/inlines.js @@ -884,7 +884,6 @@ var parseReference = function(s, refmap) { title = this.parseLinkTitle(); } if (title === null) { - title = ""; // rewind before spaces this.pos = beforetitle; } @@ -892,13 +891,13 @@ var parseReference = function(s, refmap) { // make sure we're at line end: var atLineEnd = true; if (this.match(reSpaceAtEndOfLine) === null) { - if (title === "") { + if (title === null) { atLineEnd = false; } else { // the potential title we found is not at the line end, // but it could still be a legal link reference if we // discard the title - title = ""; + title = null; // rewind before spaces this.pos = beforetitle; // and instead check if the link URL is at the line end @@ -919,7 +918,7 @@ var parseReference = function(s, refmap) { } if (!refmap[normlabel]) { - refmap[normlabel] = { destination: dest, title: title }; + refmap[normlabel] = { destination: dest, title: title === null ? "" : title }; } return this.pos - startpos; }; diff --git a/test/regression.txt b/test/regression.txt index da235fb2..aea81378 100644 --- a/test/regression.txt +++ b/test/regression.txt @@ -484,3 +484,11 @@ x <- 1

&para

ΒΆ

```````````````````````````````` + +#281 +```````````````````````````````` example +[test]:example +""third [test] +. +

""third test

+```````````````````````````````` \ No newline at end of file