Skip to content

Commit

Permalink
Normalize Windows-style path separators to forward slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
hmarr committed Feb 3, 2023
1 parent 09e871d commit fbcff39
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions match.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package codeowners

import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
)
Expand Down Expand Up @@ -32,6 +32,9 @@ func newPattern(patternStr string) (pattern, error) {

// match tests if the path provided matches the pattern
func (p pattern) match(testPath string) (bool, error) {
// Normalize Windows-style path separators to forward slashes
testPath = filepath.ToSlash(testPath)

if p.leftAnchoredLiteral {
prefix := p.pattern

Expand All @@ -51,7 +54,7 @@ func (p pattern) match(testPath string) (bool, error) {
}

// Otherwise check if the test path is a subdirectory of the pattern
if len(testPath) > len(prefix) && testPath[len(prefix)] == os.PathSeparator {
if len(testPath) > len(prefix) && testPath[len(prefix)] == '/' {
return testPath[:len(prefix)] == prefix, nil
}

Expand Down

0 comments on commit fbcff39

Please sign in to comment.