Skip to content

Commit 914e837

Browse files
joshbetzmcarmonaa
authored andcommitted
Normalize filenames before comparing.
Some multibyte characters can have multiple representations. Before comparing strings, we need to normalize them. In this case we're normalizing to normalized form C, but it shouldn't matter as long as both strings are normalized to the same form. Fixes src-d#495
1 parent a0885c5 commit 914e837

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

utils/merkletrie/noder/path.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package noder
33
import (
44
"bytes"
55
"strings"
6+
7+
"golang.org/x/text/unicode/norm"
68
)
79

810
// Path values represent a noder and its ancestors. The root goes first
@@ -78,7 +80,11 @@ func (p Path) Compare(other Path) int {
7880
case i == len(p):
7981
return -1
8082
default:
81-
cmp := strings.Compare(p[i].Name(), other[i].Name())
83+
form := norm.Form(norm.NFC)
84+
this := form.String(p[i].Name())
85+
that := form.String(other[i].Name())
86+
87+
cmp := strings.Compare(this, that)
8288
if cmp != 0 {
8389
return cmp
8490
}

0 commit comments

Comments
 (0)