Fix explicit line break parsing

It's possible for the input to end right after the explicit line break,
i.e. after the second \. This currently leads to an out of range index into
input (as the for loop starts with start+2 and [start:start+1] is the \\).
This commit is contained in:
Niklas Fasching 2019-01-12 20:03:26 +01:00
parent 00d5a9cdd2
commit da99094e20
4 changed files with 7 additions and 4 deletions

View file

@ -129,7 +129,7 @@ func (d *Document) parseLineBreak(input string, start int) (int, Node) {
} }
func (d *Document) parseExplicitLineBreak(input string, start int) (int, Node) { func (d *Document) parseExplicitLineBreak(input string, start int) (int, Node) {
if start == 0 || input[start-1] == '\n' || start+1 >= len(input) || input[start+1] != '\\' { if start == 0 || input[start-1] == '\n' || start+2 >= len(input) || input[start+1] != '\\' {
return 0, nil return 0, nil
} }
for i := start + 2; unicode.IsSpace(rune(input[i])); i++ { for i := start + 2; unicode.IsSpace(rune(input[i])); i++ {

View file

@ -2,7 +2,8 @@
<li> <li>
<p> <p>
<em>emphasis</em> and a hard line break <br> <em>emphasis</em> and a hard line break <br>
see? see? <br>
also hard line breaks not followed by a newline get ignored, see \\
</p> </p>
</li> </li>
<li> <li>

View file

@ -1,5 +1,6 @@
- /emphasis/ and a hard line break \\ - /emphasis/ and a hard line break \\
see? see? \\
also hard line breaks not followed by a newline get ignored, see \\
- /.emphasis with dot border chars./ - /.emphasis with dot border chars./
- /emphasis with a slash/inside/ - /emphasis with a slash/inside/
- /emphasis/ followed by raw text with slash / - /emphasis/ followed by raw text with slash /

View file

@ -1,5 +1,6 @@
- /emphasis/ and a hard line break \\ - /emphasis/ and a hard line break \\
see? see? \\
also hard line breaks not followed by a newline get ignored, see \\
- /.emphasis with dot border chars./ - /.emphasis with dot border chars./
- /emphasis with a slash/inside/ - /emphasis with a slash/inside/
- /emphasis/ followed by raw text with slash / - /emphasis/ followed by raw text with slash /