Skip to content

Commit bd19ed7

Browse files
author
Harry Marr
authored
Merge pull request #16 from hmarr/windows-ci
Windows support
2 parents e554638 + fbcff39 commit bd19ed7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ on:
99
jobs:
1010
build:
1111
name: Build
12-
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest]
15+
runs-on: ${{ matrix.os }}
1316
steps:
14-
1517
- name: Set up Go 1.x
1618
uses: actions/setup-go@v3
1719
with:

match.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package codeowners
22

33
import (
44
"fmt"
5-
"os"
5+
"path/filepath"
66
"regexp"
77
"strings"
88
)
@@ -17,7 +17,7 @@ type pattern struct {
1717
func 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
3434
func (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

Comments
 (0)