Fix ExplicitLineBreak parsing

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).
This commit is contained in:
Niklas Fasching 2019-10-29 01:03:10 +01:00
parent 14900e97e2
commit 4292628c80
4 changed files with 18 additions and 4 deletions

View file

@ -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{}
}
}

View file

@ -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>
@ -499,7 +501,13 @@ index out of range in headline priority parsing
<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">

View file

@ -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*

View file

@ -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*