Skip to content

Commit 9310192

Browse files
authored
fix: GlobDistance handles / and * correctly (#281)
Fixes the long-standing bug in #63.
1 parent b25a781 commit 9310192

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎internal/strdist/strdist.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,17 @@ func globCost(ar, br rune) Cost {
123123
if ar == '⁑' || br == '⁑' {
124124
return Cost{SwapAB: 0, DeleteA: 0, InsertB: 0}
125125
}
126-
if ar == '/' || br == '/' {
127-
return Cost{SwapAB: Inhibit, DeleteA: Inhibit, InsertB: Inhibit}
126+
if ar == '*' && br == '/' {
127+
return Cost{SwapAB: Inhibit, DeleteA: 0, InsertB: Inhibit}
128+
} else if ar == '/' && br == '*' {
129+
return Cost{SwapAB: Inhibit, DeleteA: Inhibit, InsertB: 0}
128130
}
129131
if ar == '*' || br == '*' {
130132
return Cost{SwapAB: 0, DeleteA: 0, InsertB: 0}
131133
}
134+
if ar == '/' || br == '/' {
135+
return Cost{SwapAB: Inhibit, DeleteA: Inhibit, InsertB: Inhibit}
136+
}
132137
if ar == '?' || br == '?' {
133138
return Cost{SwapAB: 0, DeleteA: 1, InsertB: 1}
134139
}

‎internal/strdist/strdist_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var distanceTests = []distanceTest{
5858
{f: strdist.GlobCost, r: 1, a: "a**f/hij", b: "abc/def/hik"},
5959
{f: strdist.GlobCost, r: 2, a: "a**fg", b: "abc/def/hik"},
6060
{f: strdist.GlobCost, r: 0, a: "a**f/hij/klm", b: "abc/d**m"},
61+
{f: strdist.GlobCost, r: 0, a: "/*a/", b: "/a/"},
6162
}
6263

6364
func (s *S) TestDistance(c *C) {

0 commit comments

Comments
 (0)