bugfix: enable case insensitivity on REs for urls and title
This commit is contained in:
1 parent
b3ca6c41ae
commit
0e58ea1282
2 files changed
+4
-3
No files matched your search
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
// a regexp which captures src/href/xhref="..." from text
|
||||
var reURL = regexp.MustCompile(`(src|href|xhref)\s*=\s*"([^"]+)"`) // TODO make RFC compliant
|
||||
var reTitle = regexp.MustCompile(`<\s*title\s*>([^<]*)`)
|
||||
var reURL = regexp.MustCompile(`(?i)(src|href|xhref)\s*=\s*"([^"]+)"`) // TODO make RFC compliant
|
||||
var reTitle = regexp.MustCompile(`(?i)<\s*title\s*>([^<]*)<\s*\/\s*title`)
|
||||
|
||||
// parse takes a string and attempts to parse any html title and all links out of it,
|
||||
// and returns a sorted slice of the captures found
|
||||
@@ -17,6 +17,7 @@ func parse(s string) (string, []string, error) {
|
||||
title := ""
|
||||
titleMatches := reTitle.FindStringSubmatch(s)
|
||||
if titleMatches != nil {
|
||||
// we found a title, replace our default title with the result
|
||||
title = strings.TrimSpace(titleMatches[1])
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
func TestSimpleParse(t *testing.T) {
|
||||
doc := `<html>
|
||||
<head>
|
||||
<title> Test Page </title>
|
||||
<TITle> Test Page </title>
|
||||
</head>
|
||||
<body>
|
||||
<img src="/assets/image.png"/>
|
||||
|
||||
Reference in new issue
Block a user