Skip to content

Commit f00dea0

Browse files
markovejnovicowlstronaut
authored andcommitted
fix: Correct tarball regex to detect literal dots
1 parent 0036ebd commit f00dea0

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/npa.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { log } = require('proc-log')
1414
const hasSlashes = isWindows ? /\\|[/]/ : /[/]/
1515
const isURL = /^(?:git[+])?[a-z]+:/i
1616
const isGit = /^[^@]+@[^:.]+\.[^:]+:.+$/i
17-
const isFileType = /[.](?:tgz|tar.gz|tar)$/i
17+
const isFileType = /[.](?:tgz|tar\.gz|tar)$/i
1818
const isPortNumber = /:[0-9]+(\/|$)/i
1919
const isWindowsFile = /^(?:[.]|~[/]|[/\\]|[a-zA-Z]:)/
2020
const isPosixFile = /^(?:[.]|~[/]|[/]|[a-zA-Z]:)/

test/basic.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,40 @@ t.test('error message', t => {
823823

824824
t.end()
825825
})
826+
827+
t.test('tarball regex should only match literal dots', t => {
828+
// Valid tarball extensions - should match
829+
t.has(normalizePaths(npa('/path/to/package.tar.gz')), {
830+
type: 'file',
831+
name: null,
832+
}, '.tar.gz should match as file')
833+
834+
t.has(normalizePaths(npa('/path/to/package.tgz')), {
835+
type: 'file',
836+
name: null,
837+
}, '.tgz should match as file')
838+
839+
t.has(normalizePaths(npa('/path/to/package.tar')), {
840+
type: 'file',
841+
name: null,
842+
}, '.tar should match as file')
843+
844+
// Invalid patterns with non-dot characters - should NOT match as file
845+
// These should be treated as directories, not files
846+
t.has(normalizePaths(npa('/path/to/package.tarXgz')), {
847+
type: 'directory',
848+
name: null,
849+
}, '.tarXgz should NOT match as file (X is not a dot)')
850+
851+
t.has(normalizePaths(npa('/path/to/package.tar_gz')), {
852+
type: 'directory',
853+
name: null,
854+
}, '.tar_gz should NOT match as file (underscore is not a dot)')
855+
856+
t.has(normalizePaths(npa('./package.tar gz')), {
857+
type: 'directory',
858+
name: null,
859+
}, '.tar gz should NOT match as file (space is not a dot)')
860+
861+
t.end()
862+
})

0 commit comments

Comments
 (0)