[MM-30344] utils/markdown: fix index out of range (#16250)
* utils/markdown: fix index out of range * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
df906cad9d
Коммит
9283143c3b
@@ -147,7 +147,7 @@ func parseImageDimensions(markdown string, position int) (raw Range, next int, o
|
|||||||
|
|
||||||
// Read width
|
// Read width
|
||||||
hasWidth := false
|
hasWidth := false
|
||||||
for isNumericByte(markdown[position]) {
|
for position < len(markdown)-1 && isNumericByte(markdown[position]) {
|
||||||
hasWidth = true
|
hasWidth = true
|
||||||
position += 1
|
position += 1
|
||||||
}
|
}
|
||||||
@@ -158,14 +158,14 @@ func parseImageDimensions(markdown string, position int) (raw Range, next int, o
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read the x
|
// Read the x
|
||||||
if markdown[position] != 'x' && markdown[position] != 'X' {
|
if (markdown[position] != 'x' && markdown[position] != 'X') || position == len(markdown)-1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
position += 1
|
position += 1
|
||||||
|
|
||||||
// Read height
|
// Read height
|
||||||
hasHeight := false
|
hasHeight := false
|
||||||
for isNumericByte(markdown[position]) {
|
for position < len(markdown)-1 && isNumericByte(markdown[position]) {
|
||||||
hasHeight = true
|
hasHeight = true
|
||||||
position += 1
|
position += 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,6 +136,27 @@ func TestParseImageDimensions(t *testing.T) {
|
|||||||
ExpectedNext: 0,
|
ExpectedNext: 0,
|
||||||
ExpectedOk: false,
|
ExpectedOk: false,
|
||||||
},
|
},
|
||||||
|
"garbage 5": {
|
||||||
|
Input: ` {
|
t.Run(name, func(t *testing.T) {
|
||||||
raw, next, ok := parseImageDimensions(tc.Input, tc.Position)
|
raw, next, ok := parseImageDimensions(tc.Input, tc.Position)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user