@@ -2,7 +2,7 @@ package codeowners
22
33import (
44 "fmt"
5- "os "
5+ "path/filepath "
66 "regexp"
77 "strings"
88)
@@ -17,7 +17,7 @@ type pattern struct {
1717func newPattern (patternStr string ) (pattern , error ) {
1818 pat := pattern {pattern : patternStr }
1919
20- if ! strings .ContainsAny (patternStr , "*?\\ " ) && patternStr [0 ] == os . PathSeparator {
20+ if ! strings .ContainsAny (patternStr , "*?\\ " ) && patternStr [0 ] == '/' {
2121 pat .leftAnchoredLiteral = true
2222 } else {
2323 patternRegex , err := buildPatternRegex (patternStr )
@@ -32,16 +32,19 @@ func newPattern(patternStr string) (pattern, error) {
3232
3333// match tests if the path provided matches the pattern
3434func (p pattern ) match (testPath string ) (bool , error ) {
35+ // Normalize Windows-style path separators to forward slashes
36+ testPath = filepath .ToSlash (testPath )
37+
3538 if p .leftAnchoredLiteral {
3639 prefix := p .pattern
3740
3841 // Strip the leading slash as we're anchored to the root already
39- if prefix [0 ] == os . PathSeparator {
42+ if prefix [0 ] == '/' {
4043 prefix = prefix [1 :]
4144 }
4245
4346 // If the pattern ends with a slash we can do a simple prefix match
44- if prefix [len (prefix )- 1 ] == os . PathSeparator {
47+ if prefix [len (prefix )- 1 ] == '/' {
4548 return strings .HasPrefix (testPath , prefix ), nil
4649 }
4750
@@ -51,7 +54,7 @@ func (p pattern) match(testPath string) (bool, error) {
5154 }
5255
5356 // Otherwise check if the test path is a subdirectory of the pattern
54- if len (testPath ) > len (prefix ) && testPath [len (prefix )] == os . PathSeparator {
57+ if len (testPath ) > len (prefix ) && testPath [len (prefix )] == '/' {
5558 return testPath [:len (prefix )] == prefix , nil
5659 }
5760
@@ -95,7 +98,7 @@ func buildPatternRegex(pattern string) (*regexp.Regexp, error) {
9598 segs [len (segs )- 1 ] = "**"
9699 }
97100
98- sep := string ( os . PathSeparator )
101+ sep := "/"
99102
100103 lastSegIndex := len (segs ) - 1
101104 needSlash := false
0 commit comments