Skip to content

Commit 2c13404

Browse files
jridgewelldignifiedquire
authored andcommitted
fix(reporter): do not allow URL domains to span new lines
This was causing some excruciating error logs with the default format of cross-domain iframe errors: ``` Error: Blocked a frame with origin "http://localhost:9876" from accessing a cross-origin frame. at Error (native) at Function.method.restore (absolute/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/fa96dc8102e4c5416f4cd38061107a08.browserify?f4458f57b50ae627f718945da619dae7c682b4a0:60376:28) at each (absolute/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/fa96dc8102e4c5416f4cd38061107a08.browserify?f4458f57b50ae627f718945da619dae7c682b4a0:57875:33) at Object.restore (absolute/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/fa96dc8102e4c5416f4cd38061107a08.browserify?f4458f57b50ae627f718945da619dae7c682b4a0:57895:17) at Object.restore (absolute/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/fa96dc8102e4c5416f4cd38061107a08.browserify?f4458f57b50ae627f718945da619dae7c682b4a0:59163:42) at Context.<anonymous> (absolute/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/fa96dc8102e4c5416f4cd38061107a08.browserify?f4458f57b50ae627f718945da619dae7c682b4a0:109551:13) ``` The old regex would find that `https://` then include everything that wasn't a slash, which included the next two lines into the `/absolute`. The output would be similar to: ``` Error: Blocked a frame with origin "/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/afde9a0a28f71236ac3340462d6ca94e.browserify:60376:28 <- node_modules/sinon/lib/sinon/util/core.js:154:0) at each (/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/afde9a0a28f71236ac3340462d6ca94e.browserify:57875:33 <- node_modules/sinon/lib/sinon/collection.js:34:0) ... ``` With this, we prevent the domain from spanning the newline character, and now the output is: ``` Error: Blocked a frame with origin "http://localhost:9876" from accessing a cross-origin frame. at Error (native) at Function.method.restore (/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/6c039bf5162f620e4d2667e56f143a02.browserify:60376:28 <- node_modules/sinon/lib/sinon/util/core.js:154:0) at each (/var/folders/8m/vg2kf8h50bj9gy5r9gwn20dw00_y0z/T/6c039bf5162f620e4d2667e56f143a02.browserify:57875:33 <- node_modules/sinon/lib/sinon/collection.js:34:0) ... ```
1 parent 9fae5e8 commit 2c13404

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/reporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var createErrorFormatter = function (config, emitter, SourceMapConsumer) {
2525
return null
2626
}
2727

28-
var URL_REGEXP = new RegExp('(?:https?:\\/\\/[^\\/]*)?\\/?' +
28+
var URL_REGEXP = new RegExp('(?:https?:\\/\\/[^\\/\\s]*)?\\/?' +
2929
'(base/|absolute)' + // prefix, including slash for base/ to create relative paths.
3030
'((?:[A-z]\\:)?[^\\?\\s\\:]*)' + // path
3131
'(\\?\\w*)?' + // sha

test/unit/reporter.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,21 @@ describe('reporter', () => {
245245
})
246246
})
247247

248+
it('should not try to match domains with spaces', (done) => {
249+
formatError = m.createErrorFormatter({ basePath: '/some/base' }, emitter, MockSourceMapConsumer)
250+
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
251+
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
252+
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}
253+
254+
emitter.emit('file_list_modified', {served: servedFiles})
255+
256+
_.defer(() => {
257+
var ERROR = '"http://localhost:9876"\n at /base/b.js:2:6'
258+
expect(formatError(ERROR)).to.equal('"http://localhost:9876"\n at /original/b.js:4:8 <- b.js:2:6\n')
259+
done()
260+
})
261+
})
262+
248263
describe('Windows', () => {
249264
formatError = null
250265
var servedFiles = null

0 commit comments

Comments
 (0)