mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
remove dependency on less function
This commit is contained in:
parent
cd7b952148
commit
4a17a5b58f
|
@ -634,7 +634,7 @@ func isSafeLink(link []byte) bool {
|
||||||
for _, prefix := range validUris {
|
for _, prefix := range validUris {
|
||||||
// TODO: handle unicode here
|
// TODO: handle unicode here
|
||||||
// case-insensitive prefix test
|
// case-insensitive prefix test
|
||||||
if len(link) > len(prefix) && !less(link[:len(prefix)], prefix) && !less(prefix, link[:len(prefix)]) && isalnum(link[len(prefix)]) {
|
if len(link) > len(prefix) && bytes.Equal(bytes.ToLower(link[:len(prefix)]), prefix) && isalnum(link[len(prefix)]) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
markdown.go
28
markdown.go
|
@ -14,7 +14,6 @@ package blackfriday
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"unicode"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are the supported markdown parsing extensions.
|
// These are the supported markdown parsing extensions.
|
||||||
|
@ -275,33 +274,6 @@ type reference struct {
|
||||||
title []byte
|
title []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare two []byte values (case-insensitive), returning
|
|
||||||
// true if a is less than b.
|
|
||||||
func less(a []byte, b []byte) bool {
|
|
||||||
// adapted from bytes.Compare in stdlib
|
|
||||||
m := len(a)
|
|
||||||
if m > len(b) {
|
|
||||||
m = len(b)
|
|
||||||
}
|
|
||||||
for i, ac := range a[0:m] {
|
|
||||||
// do a case-insensitive comparison
|
|
||||||
ai, bi := unicode.ToLower(int(ac)), unicode.ToLower(int(b[i]))
|
|
||||||
switch {
|
|
||||||
case ai > bi:
|
|
||||||
return false
|
|
||||||
case ai < bi:
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case len(a) < len(b):
|
|
||||||
return true
|
|
||||||
case len(a) > len(b):
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether or not data starts with a reference link.
|
// Check whether or not data starts with a reference link.
|
||||||
// If so, it is parsed and stored in the list of references
|
// If so, it is parsed and stored in the list of references
|
||||||
// (in the render struct).
|
// (in the render struct).
|
||||||
|
|
Loading…
Reference in New Issue
Block a user