summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorAdrian <adrian@planetcoding.net>2018-07-19 04:55:50 +0200
committerChristopher Speller <crspeller@gmail.com>2018-07-18 19:55:50 -0700
commita575411f159d3e63b91fd4a03b448d3f52862747 (patch)
treea42c65328668b6fd68fdb331281e8d7e341d8bf3 /utils
parent5a2d46c6cbf992c8a8f155b27eb3b60807d8aed2 (diff)
downloadchat-a575411f159d3e63b91fd4a03b448d3f52862747.tar.gz
chat-a575411f159d3e63b91fd4a03b448d3f52862747.tar.bz2
chat-a575411f159d3e63b91fd4a03b448d3f52862747.zip
Fix invalid markdown text ranges (#9126)
second Range value is the end pos, not the length... :see_no_evil:
Diffstat (limited to 'utils')
-rw-r--r--utils/markdown/inlines.go4
-rw-r--r--utils/markdown/text_range_test.go11
2 files changed, 10 insertions, 5 deletions
diff --git a/utils/markdown/inlines.go b/utils/markdown/inlines.go
index 02ef47e24..9198435ee 100644
--- a/utils/markdown/inlines.go
+++ b/utils/markdown/inlines.go
@@ -427,7 +427,7 @@ func (p *inlineParser) parseCharacterReference() {
if semicolon := strings.IndexByte(p.raw[p.position:], ';'); semicolon == -1 {
p.inlines = append(p.inlines, &Text{
Text: "&",
- Range: Range{absPos, 1},
+ Range: Range{absPos, absPos + 1},
})
} else if s := CharacterReference(p.raw[p.position : p.position+semicolon]); s != "" {
p.position += semicolon + 1
@@ -438,7 +438,7 @@ func (p *inlineParser) parseCharacterReference() {
} else {
p.inlines = append(p.inlines, &Text{
Text: "&",
- Range: Range{absPos, 1},
+ Range: Range{absPos, absPos + 1},
})
}
}
diff --git a/utils/markdown/text_range_test.go b/utils/markdown/text_range_test.go
index 25c13c40d..de3dd0985 100644
--- a/utils/markdown/text_range_test.go
+++ b/utils/markdown/text_range_test.go
@@ -86,9 +86,14 @@ func TestTextRanges(t *testing.T) {
ExpectedValues: []string{"&amp test"},
},
"notcharref2": {
- Markdown: "&mattermost;",
- ExpectedRanges: []Range{{0, 12}},
- ExpectedValues: []string{"&mattermost;"},
+ Markdown: "this is &mattermost;",
+ ExpectedRanges: []Range{{0, 20}},
+ ExpectedValues: []string{"this is &mattermost;"},
+ },
+ "standalone-ampersand": {
+ Markdown: "Hello & World",
+ ExpectedRanges: []Range{{0, 13}},
+ ExpectedValues: []string{"Hello & World"},
},
} {
t.Run(name, func(t *testing.T) {