]> Sergey Matveev's repositories - path-extractor.git/commitdiff
Works with shebangs
authorEdgar HIPP <hipp.edg@gmail.com>
Sun, 30 Aug 2015 15:07:05 +0000 (17:07 +0200)
committerEdgar HIPP <hipp.edg@gmail.com>
Sun, 30 Aug 2015 15:07:05 +0000 (17:07 +0200)
extractor.go
pe_test.go

index 19bc27472cea37b8466450dc342317bfa9e85650..a0d43dd822b4561fed3c59ccbb0da5d5c5463d89 100644 (file)
@@ -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)
index acb93c13b04ede10c558f6e517ecb49d5ebcfc73..c88aa0d5dee7ba52f7ff90bb214e1f5f5d60c1ea 100644 (file)
@@ -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)