From: Edgar HIPP Date: Sun, 30 Aug 2015 15:07:05 +0000 (+0200) Subject: Works with shebangs X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=abcf2195612d2ce3408816a36330472f4b06ece3;p=path-extractor.git Works with shebangs --- diff --git a/extractor.go b/extractor.go index 19bc274..a0d43dd 100644 --- a/extractor.go +++ b/extractor.go @@ -9,7 +9,7 @@ type MatchOptions struct { } func pathExtractor(input string) [][][]byte { - surroundRegex := "[^]()[ \\t:'\"]*" + surroundRegex := "[^]()!#[ \\t:'\"]*" r := regexp.MustCompile("(" + surroundRegex + "[\\./]" + surroundRegex + ")") temp := [][][]byte{} temp = r.FindAllSubmatch([]byte(input), -1) diff --git a/pe_test.go b/pe_test.go index acb93c1..c88aa0d 100644 --- a/pe_test.go +++ b/pe_test.go @@ -13,6 +13,14 @@ func TestEverything(t *testing.T) { t.Errorf("Matches sentence", output) } + output = GetAllMatches("!#/usr/bin/env", MatchOptions{}) + if len(output) != 1 { + t.Errorf("Doesn't match shebang", output) + } + if output[0] != "/usr/bin/env" { + t.Errorf("Doesn't match shebang", output) + } + output = GetAllMatches("hello .gitignore", MatchOptions{}) if output[0] != ".gitignore" { t.Errorf("Doesnt match hidden files", output)