Skip to content

Commit

Permalink
fix: path matches on Windows (#170)
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <[email protected]>
  • Loading branch information
greut authored Sep 27, 2023
1 parent de7896a commit 7354273
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
7 changes: 1 addition & 6 deletions editorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"os"
"runtime"
"strings"

"gopkg.in/ini.v1"
Expand Down Expand Up @@ -122,11 +121,7 @@ func (e *Editorconfig) GetDefinitionForFilename(name string) (*Definition, error
}

if !strings.HasPrefix(name, "/") {
if runtime.GOOS != "windows" {
name = "/" + name
} else {
name = "\\" + name
}
name = "/" + name
}

ok, err := e.FnmatchCase(selector, name)
Expand Down
7 changes: 1 addition & 6 deletions fnmatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package editorconfig
import (
"fmt"
"regexp"
"runtime"
"strconv"
"strings"
)
Expand Down Expand Up @@ -33,7 +32,7 @@ func FnmatchCase(pattern, name string) (bool, error) {
return r.MatchString(name), nil
}

func translate(pattern string) string { //nolint:funlen,gocognit,gocyclo,cyclop,maintidx
func translate(pattern string) string { //nolint:funlen,gocognit,gocyclo,cyclop
index := 0
pat := []rune(pattern)
length := len(pat)
Expand All @@ -52,10 +51,6 @@ func translate(pattern string) string { //nolint:funlen,gocognit,gocyclo,cyclop,
matchesBraces := left+doubleLeft == right+doubleRight
pathSeparator := "/"

if runtime.GOOS == "windows" {
pathSeparator = regexp.QuoteMeta("\\")
}

for index < length {
r := pat[index]
index++
Expand Down

0 comments on commit 7354273

Please sign in to comment.