Fix panic in markdown link parsing (#10785)

This commit is contained in:
Joram Wilander
2019-05-07 09:14:35 -04:00
committed by GitHub
parent 4f7f7070c0
commit efe9d0a5f8
2 changed files with 16 additions and 0 deletions
+4
View File
@@ -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:]) {
+12
View File
@@ -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 {