Skip to content

Commit

Permalink
fix: clean asset url with regex (#886)
Browse files Browse the repository at this point in the history
Fixes: #878
  • Loading branch information
subzero10 authored Sep 20, 2022
1 parent c5aff95 commit 9c0032b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/webpack/src/HoneybadgerSourceMapPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ class HoneybadgerSourceMapPlugin {

getUrlToAsset (sourceFile) {
if (typeof sourceFile === 'string') {
const sep = this.assetsUrl.endsWith('/') ? '' : '/'
return `${this.assetsUrl}${sep}${sourceFile}`
const sep = '/'
const unsanitized = `${this.assetsUrl}${sep}${sourceFile}`
return unsanitized.replace(/([^:]\/)\/+/g, '$1')
}
return this.assetsUrl(sourceFile)
}
Expand Down
15 changes: 15 additions & 0 deletions packages/webpack/test/HoneybadgerSourceMapPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,21 @@ describe(PLUGIN_NAME, function () {
await plugin.uploadSourceMap(compilation, chunk)
expect(this.info.calledWith('Uploaded vendor.5190.js.map to Honeybadger API')).to.eq(true)
})

it('should build correct assert url', function () {
const sourceFile1 = '/js/app.js'
const sourceFile2 = 'js/app.js'

const plugin = new HoneybadgerSourceMapPlugin({ assetsUrl: 'https://example.com' });
expect(plugin.assetsUrl).to.eq('https://example.com')
expect(plugin.getUrlToAsset(sourceFile1)).to.eq('https://example.com/js/app.js')
expect(plugin.getUrlToAsset(sourceFile2)).to.eq('https://example.com/js/app.js')

plugin.assetsUrl = 'https://example.com/'
expect(plugin.assetsUrl).to.eq('https://example.com/')
expect(plugin.getUrlToAsset(sourceFile1)).to.eq('https://example.com/js/app.js')
expect(plugin.getUrlToAsset(sourceFile2)).to.eq('https://example.com/js/app.js')
})
})

describe('sendDeployNotification', function () {
Expand Down

0 comments on commit 9c0032b

Please sign in to comment.