From da99094e202fce609081d78ca8d38d5b010a0274 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Sat, 12 Jan 2019 20:03:26 +0100 Subject: [PATCH] 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 \\). --- org/inline.go | 2 +- org/testdata/inline.html | 3 ++- org/testdata/inline.org | 3 ++- org/testdata/inline.pretty_org | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/org/inline.go b/org/inline.go index d4c8c43..ab58b7b 100644 --- a/org/inline.go +++ b/org/inline.go @@ -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++ { diff --git a/org/testdata/inline.html b/org/testdata/inline.html index 3cbb95b..9801b36 100644 --- a/org/testdata/inline.html +++ b/org/testdata/inline.html @@ -2,7 +2,8 @@
  • emphasis and a hard line break
    -see? +see?
    +also hard line breaks not followed by a newline get ignored, see \\

  • diff --git a/org/testdata/inline.org b/org/testdata/inline.org index 7097358..d967879 100644 --- a/org/testdata/inline.org +++ b/org/testdata/inline.org @@ -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 / diff --git a/org/testdata/inline.pretty_org b/org/testdata/inline.pretty_org index f4429e9..f1320bb 100644 --- a/org/testdata/inline.pretty_org +++ b/org/testdata/inline.pretty_org @@ -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 /