Skip to content

Commit

Permalink
Fix title-related backtracking with empty string
Browse files Browse the repository at this point in the history
Fixes #281
  • Loading branch information
notriddle authored and jgm committed Feb 3, 2024
1 parent ba128a8 commit 3ef341b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/inlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,21 +884,20 @@ var parseReference = function(s, refmap) {
title = this.parseLinkTitle();
}
if (title === null) {
title = "";
// rewind before spaces
this.pos = beforetitle;
}

// 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
Expand All @@ -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;
};
Expand Down
8 changes: 8 additions & 0 deletions test/regression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,11 @@ x <- 1
<p>&amp;para</p>
<p>¶</p>
````````````````````````````````

#281
```````````````````````````````` example
[test]:example
""third [test]
.
<p>&quot;&quot;third <a href="example">test</a></p>
````````````````````````````````

0 comments on commit 3ef341b

Please sign in to comment.