Fix panic in markdown link parsing (#10785)

Этот коммит содержится в:
Joram Wilander
2019-05-07 09:14:35 -04:00
коммит произвёл GitHub
родитель 4f7f7070c0
Коммит efe9d0a5f8
2 изменённых файлов: 16 добавлений и 0 удалений

Просмотреть файл

@@ -78,6 +78,10 @@ func parseURLAutolink(data string, position int) (Range, bool) {
start -= 1
}
if start < 0 || position >= len(data) {
return Range{}, false
}
// Ensure that the URL scheme is allowed and that at least one character after the scheme is valid.
scheme := data[start:position]
if !isSchemeAllowed(scheme) || !isValidHostCharacter(data[position+3:]) {

Просмотреть файл

@@ -130,6 +130,18 @@ func TestParseURLAutolink(t *testing.T) {
Position: 14,
Expected: "http://example.com",
},
{
Description: "bad link protocol",
Input: "://///",
Position: 0,
Expected: "",
},
{
Description: "position greater than input length",
Input: "there is no colon",
Position: 1000,
Expected: "",
},
}
for _, testCase := range testCases {