Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Prevent asbolute webpack:/// paths from being relatively resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
bengourley committed Nov 1, 2019
1 parent 95acc11 commit c776d2d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function transformSourcesMap (options) {
readFileJSON(options.sourceMap)
.then(sourceMap => (
mapSources(sourceMap, p => {
// don't transform any webpack paths
if (/^webpack:\/\//.test(p)) return p

// resolve a relative path in the sources array
const resolvedPath = path.resolve(path.dirname(options.sourceMap), p)

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/webpack/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/webpack/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,36 @@ test('multiple uploads (resolving relative source paths inside map)', () => {
])
})
})

test('webpack paths', () => {
let mockCalled = 0
let mockCalledWith = []
const mockConcat = concat
jest.mock('../lib/request', () => {
return (endpoint, makePayload, onSuccess, onError) => {
mockCalled++
const payload = makePayload()
payload.sourceMap.pipe(mockConcat(data => {
payload.sourceMapData = JSON.parse(data)
mockCalledWith.push(payload)
onSuccess()
}))
}
})

const upload = require('../').upload
return upload({
apiKey: 'API_KEY',
projectRoot: `${__dirname}/fixtures/webpack`,
sourceMap: `${__dirname}/fixtures/webpack/main.js.map`,
minifiedFile: `${__dirname}/fixtures/webpack/main.js`,
minifiedUrl: 'http://yeah.no/bundle.js'
}).then(() => {
expect(mockCalled).toBe(1)

expect(mockCalledWith[0].sourceMapData.sources).toEqual([
'webpack:///webpack/bootstrap',
'webpack:///./src/index.js'
])
})
})

0 comments on commit c776d2d

Please sign in to comment.