From 0e58ea12822623f12b0c3d93e7dd4876d8fa5822 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 15 Feb 2015 08:07:42 -0800 Subject: [PATCH] bugfix: enable case insensitivity on REs for urls and title --- src/docrawler/parse.go | 5 +++-- src/docrawler/parse_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/docrawler/parse.go b/src/docrawler/parse.go index e03a667..13a1010 100644 --- a/src/docrawler/parse.go +++ b/src/docrawler/parse.go @@ -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]) } diff --git a/src/docrawler/parse_test.go b/src/docrawler/parse_test.go index eae5883..9089d55 100644 --- a/src/docrawler/parse_test.go +++ b/src/docrawler/parse_test.go @@ -8,7 +8,7 @@ import ( func TestSimpleParse(t *testing.T) { doc := ` - Test Page + Test Page