Skip to content

Commit

Permalink
Avoid locale-dependent sorting issues
Browse files Browse the repository at this point in the history
Force all uses of String.localeCompare to use the 'en' locale.

Re: npm/cli#2829
  • Loading branch information
isaacs committed May 6, 2021
1 parent 0a64e2d commit 36c7668
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ const sort = (a, b) => {
const basea = path.basename(a).toLowerCase()
const baseb = path.basename(b).toLowerCase()

return exta.localeCompare(extb) ||
basea.localeCompare(baseb) ||
a.localeCompare(b)
return exta.localeCompare(extb, 'en') ||
basea.localeCompare(baseb, 'en') ||
a.localeCompare(b, 'en')
}

module.exports = walk
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"url": "git+https://github.com/npm/npm-packlist.git"
},
"tap": {
"test-env": [
"LC_ALL=sk"
],
"check-coverage": true,
"nyc-arg": [
"--include=index.js",
Expand Down
3 changes: 3 additions & 0 deletions tap-snapshots/test/sorting.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Array [
"a/b/1",
"node_modules/a/b/c",
"node_modules/b/c",
"cat",
"chai",
"dog",
"a/b/c/d/e/f/g",
"a/b/x/y",
"asdf.js",
Expand Down
3 changes: 3 additions & 0 deletions test/sorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const sort = Walker.prototype.sort

t.matchSnapshot([
'a/b/1',
'cat',
'dog',
'chai',
'package.json',
'node_modules/b/c',
'asdf.js',
Expand Down

0 comments on commit 36c7668

Please sign in to comment.