Skip to content

Commit

Permalink
fix: apply slash normalizer before bin path join (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored May 2, 2023
1 parent 148c452 commit 1ebb83b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const normalizeObject = pkg => {
return
}

const binTarget = join('/', orig[binKey])
const binTarget = join('/', orig[binKey].replace(/\\/g, '/'))
.replace(/\\/g, '/').slice(1)

if (!binTarget) {
Expand Down
7 changes: 7 additions & 0 deletions test/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ t.test('dotty array', async t => {
t.strictSame(normalize(pkg), expect)
t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
})

t.test('dotty array with backslashes', async t => {
const pkg = { name: 'hello', version: 'world', bin: ['..\\..\\..\\..\\etc\\passwd'] }
const expect = { name: 'hello', version: 'world', bin: { passwd: 'etc/passwd' } }
t.strictSame(normalize(pkg), expect)
t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
})
7 changes: 7 additions & 0 deletions test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ t.test('dotty string', async t => {
t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
})

t.test('dotty string with backslashes', async t => {
const pkg = { name: 'hello', version: 'world', bin: '..\\..\\..\\..\\etc\\passwd' }
const expect = { name: 'hello', version: 'world', bin: { hello: 'etc/passwd' } }
t.strictSame(normalize(pkg), expect)
t.strictSame(normalize(normalize(pkg)), expect, 'double sanitize ok')
})

t.test('double path', async t => {
const pkg = { name: 'hello', version: 'world', bin: '/etc/passwd:/bin/usr/exec' }
const expect = { name: 'hello', version: 'world', bin: { hello: 'etc/passwd:/bin/usr/exec' } }
Expand Down

0 comments on commit 1ebb83b

Please # to comment.