Skip to content

Commit 7beca13

Browse files
committed
Does no load source map file without opts.from
1 parent decea51 commit 7beca13

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

lib/previous-map.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,13 @@ class PreviousMap {
8686

8787
loadFile(path, cssFile, trusted) {
8888
if (!trusted && !this.unsafeMap) {
89-
if (!/\.map$/i.test(path)) {
89+
if (!/\.map$/i.test(path)) return undefined
90+
if (!cssFile) return undefined
91+
92+
let rel = relative(dirname(cssFile), path)
93+
if (rel === '..' || rel.startsWith('..' + sep) || isAbsolute(rel)) {
9094
return undefined
9195
}
92-
if (cssFile) {
93-
let relativePath = relative(dirname(cssFile), path)
94-
if (
95-
relativePath === '..' ||
96-
relativePath.startsWith('..' + sep) ||
97-
isAbsolute(relativePath)
98-
) {
99-
return undefined
100-
}
101-
}
10296
}
10397
this.root = dirname(path)
10498
if (existsSync(path)) {

test/previous-map.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,21 @@ test('does not load map from outside the from folder', () => {
313313
type(input?.map, 'undefined')
314314
})
315315

316+
test('does not load relative map without from', () => {
317+
let cwd = join(dir, 'subdir')
318+
mkdirSync(dir)
319+
mkdirSync(cwd)
320+
writeFileSync(join(cwd, 'previous.map'), map)
321+
let previousCwd = process.cwd()
322+
try {
323+
process.chdir(cwd)
324+
let input = parse('a{}\n/*# sourceMappingURL=previous.map */').source?.input
325+
type(input?.map, 'undefined')
326+
} finally {
327+
process.chdir(previousCwd)
328+
}
329+
})
330+
316331
test('loads map from outside the from folder with unsafeMap', () => {
317332
let from = join(dir, 'subdir', 'a.css')
318333
mkdirSync(dir)

0 commit comments

Comments
 (0)