Fix invalid markdown text ranges (#9126)
second Range value is the end pos, not the length... 🙈
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
5a2d46c6cb
Коммит
a575411f15
@@ -427,7 +427,7 @@ func (p *inlineParser) parseCharacterReference() {
|
|||||||
if semicolon := strings.IndexByte(p.raw[p.position:], ';'); semicolon == -1 {
|
if semicolon := strings.IndexByte(p.raw[p.position:], ';'); semicolon == -1 {
|
||||||
p.inlines = append(p.inlines, &Text{
|
p.inlines = append(p.inlines, &Text{
|
||||||
Text: "&",
|
Text: "&",
|
||||||
Range: Range{absPos, 1},
|
Range: Range{absPos, absPos + 1},
|
||||||
})
|
})
|
||||||
} else if s := CharacterReference(p.raw[p.position : p.position+semicolon]); s != "" {
|
} else if s := CharacterReference(p.raw[p.position : p.position+semicolon]); s != "" {
|
||||||
p.position += semicolon + 1
|
p.position += semicolon + 1
|
||||||
@@ -438,7 +438,7 @@ func (p *inlineParser) parseCharacterReference() {
|
|||||||
} else {
|
} else {
|
||||||
p.inlines = append(p.inlines, &Text{
|
p.inlines = append(p.inlines, &Text{
|
||||||
Text: "&",
|
Text: "&",
|
||||||
Range: Range{absPos, 1},
|
Range: Range{absPos, absPos + 1},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,9 +86,14 @@ func TestTextRanges(t *testing.T) {
|
|||||||
ExpectedValues: []string{"& test"},
|
ExpectedValues: []string{"& test"},
|
||||||
},
|
},
|
||||||
"notcharref2": {
|
"notcharref2": {
|
||||||
Markdown: "&mattermost;",
|
Markdown: "this is &mattermost;",
|
||||||
ExpectedRanges: []Range{{0, 12}},
|
ExpectedRanges: []Range{{0, 20}},
|
||||||
ExpectedValues: []string{"&mattermost;"},
|
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) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user