Skip to content

Commit

Permalink
Fix ExplicitLineBreak parsing
Browse files Browse the repository at this point in the history
fuzzed index out of range and moved range check into for condition as \\
followed by spaces at the end of the inline text should not be turned into an
ExplicitLineBreak (just like \\ not followed by spaces).
  • Loading branch information
niklasfasching committed Oct 29, 2019
1 parent 14900e9 commit 4292628
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions org/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func (d *Document) parseExplicitLineBreakOrLatexFragment(input string, start int
switch {
case start+2 >= len(input):
case input[start+1] == '\\' && start != 0 && input[start-1] != '\n':
for i := start + 2; unicode.IsSpace(rune(input[i])); i++ {
if i >= len(input) || input[i] == '\n' {
for i := start + 2; i <= len(input)-1 && unicode.IsSpace(rune(input[i])); i++ {
if input[i] == '\n' {
return i + 1 - start, ExplicitLineBreak{}
}
}
Expand Down
12 changes: 10 additions & 2 deletions org/testdata/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@
</li>
</ul>
</li>
<li><a href="#headline-30">index out of range in explicit line break parsing</a>
</li>
</ul>
</li>
<li><a href="#headline-30">Footnotes</a>
<li><a href="#headline-31">Footnotes</a>
</li>
</ul>
</nav>
Expand Down Expand Up @@ -499,7 +501,13 @@ <h3 id="headline-28">
<h4 id="headline-29">
[#B
</h4>
<h1 id="headline-30">
<h3 id="headline-30">
index out of range in explicit line break parsing
</h3>
<p>
0\\
</p>
<h1 id="headline-31">
Footnotes
</h1>
<div class="footnotes">
Expand Down
3 changes: 3 additions & 0 deletions org/testdata/misc.org
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09-
** misc fuzz / regression / edge case
*** index out of range in headline priority parsing
**** [#B
*** index out of range in explicit line break parsing
0\\

* Footnotes

[fn:1] a footnote /with/ *markup*
Expand Down
3 changes: 3 additions & 0 deletions org/testdata/misc.pretty_org
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ When inserting an image link like [[/home/amos/Pictures/Screenshots/img-2017-09-
** misc fuzz / regression / edge case
*** index out of range in headline priority parsing
**** [#B
*** index out of range in explicit line break parsing
0\\

* Footnotes

[fn:1] a footnote /with/ *markup*
Expand Down

0 comments on commit 4292628

Please sign in to comment.