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
|
// a regexp which captures src/href/xhref="..." from text
|
||||||
var reURL = regexp.MustCompile(`(src|href|xhref)\s*=\s*"([^"]+)"`) // TODO make RFC compliant
|
var reURL = regexp.MustCompile(`(?i)(src|href|xhref)\s*=\s*"([^"]+)"`) // TODO make RFC compliant
|
||||||
var reTitle = regexp.MustCompile(`<\s*title\s*>([^<]*)`)
|
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,
|
// 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
|
// and returns a sorted slice of the captures found
|
||||||
@@ -17,6 +17,7 @@ func parse(s string) (string, []string, error) {
|
|||||||
title := ""
|
title := ""
|
||||||
titleMatches := reTitle.FindStringSubmatch(s)
|
titleMatches := reTitle.FindStringSubmatch(s)
|
||||||
if titleMatches != nil {
|
if titleMatches != nil {
|
||||||
|
// we found a title, replace our default title with the result
|
||||||
title = strings.TrimSpace(titleMatches[1])
|
title = strings.TrimSpace(titleMatches[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
func TestSimpleParse(t *testing.T) {
|
func TestSimpleParse(t *testing.T) {
|
||||||
doc := `<html>
|
doc := `<html>
|
||||||
<head>
|
<head>
|
||||||
<title> Test Page </title>
|
<TITle> Test Page </title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<img src="/assets/image.png"/>
|
<img src="/assets/image.png"/>
|
||||||
|
|||||||
Reference in new issue
Block a user