[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
|
||||
hasWidth := false
|
||||
for isNumericByte(markdown[position]) {
|
||||
for position < len(markdown)-1 && isNumericByte(markdown[position]) {
|
||||
hasWidth = true
|
||||
position += 1
|
||||
}
|
||||
@@ -158,14 +158,14 @@ func parseImageDimensions(markdown string, position int) (raw Range, next int, o
|
||||
}
|
||||
|
||||
// Read the x
|
||||
if markdown[position] != 'x' && markdown[position] != 'X' {
|
||||
if (markdown[position] != 'x' && markdown[position] != 'X') || position == len(markdown)-1 {
|
||||
return
|
||||
}
|
||||
position += 1
|
||||
|
||||
// Read height
|
||||
hasHeight := false
|
||||
for isNumericByte(markdown[position]) {
|
||||
for position < len(markdown)-1 && isNumericByte(markdown[position]) {
|
||||
hasHeight = true
|
||||
position += 1
|
||||
}
|
||||
|
||||
@@ -136,6 +136,27 @@ func TestParseImageDimensions(t *testing.T) {
|
||||
ExpectedNext: 0,
|
||||
ExpectedOk: false,
|
||||
},
|
||||
"garbage 5": {
|
||||
Input: ` {
|
||||
raw, next, ok := parseImageDimensions(tc.Input, tc.Position)
|
||||
|
||||
Ссылка в новой задаче
Block a user