Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { log } = require('proc-log')
const hasSlashes = isWindows ? /\\|[/]/ : /[/]/
const isURL = /^(?:git[+])?[a-z]+:/i
const isGit = /^[^@]+@[^:.]+\.[^:]+:.+$/i
const isFileType = /[.](?:tgz|tar.gz|tar)$/i
const isFileType = /[.](?:tgz|tar\.gz|tar)$/i
const isPortNumber = /:[0-9]+(\/|$)/i
const isWindowsFile = /^(?:[.]|~[/]|[/\\]|[a-zA-Z]:)/
const isPosixFile = /^(?:[.]|~[/]|[/]|[a-zA-Z]:)/
Expand Down
37 changes: 37 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,40 @@ t.test('error message', t => {

t.end()
})

t.test('tarball regex should only match literal dots', t => {
// Valid tarball extensions - should match
t.has(normalizePaths(npa('/path/to/package.tar.gz')), {
type: 'file',
name: null,
}, '.tar.gz should match as file')

t.has(normalizePaths(npa('/path/to/package.tgz')), {
type: 'file',
name: null,
}, '.tgz should match as file')

t.has(normalizePaths(npa('/path/to/package.tar')), {
type: 'file',
name: null,
}, '.tar should match as file')

// Invalid patterns with non-dot characters - should NOT match as file
// These should be treated as directories, not files
t.has(normalizePaths(npa('/path/to/package.tarXgz')), {
type: 'directory',
name: null,
}, '.tarXgz should NOT match as file (X is not a dot)')

t.has(normalizePaths(npa('/path/to/package.tar_gz')), {
type: 'directory',
name: null,
}, '.tar_gz should NOT match as file (underscore is not a dot)')

t.has(normalizePaths(npa('./package.tar gz')), {
type: 'directory',
name: null,
}, '.tar gz should NOT match as file (space is not a dot)')

t.end()
})