Skip to content

Commit

Permalink
Fix explicit line break parsing
Browse files Browse the repository at this point in the history
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 \\).
  • Loading branch information
niklasfasching committed Jan 12, 2019
1 parent 00d5a9c commit da99094
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion org/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (d *Document) parseLineBreak(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
}
for i := start + 2; unicode.IsSpace(rune(input[i])); i++ {
Expand Down
3 changes: 2 additions & 1 deletion org/testdata/inline.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<li>
<p>
<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>
</li>
<li>
Expand Down
3 changes: 2 additions & 1 deletion org/testdata/inline.org
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- /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 a slash/inside/
- /emphasis/ followed by raw text with slash /
Expand Down
3 changes: 2 additions & 1 deletion org/testdata/inline.pretty_org
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- /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 a slash/inside/
- /emphasis/ followed by raw text with slash /
Expand Down

0 comments on commit da99094

Please sign in to comment.