From 1e5c561c900e7c83de2123ca6368f0bf9b2775b4 Mon Sep 17 00:00:00 2001 From: John Bacon Date: Fri, 10 Jan 2014 17:30:49 -0500 Subject: [PATCH 1/3] Update raven.js to work around IE8 shortcomings Internet Explorer 8 chokes on an undefined or null reference passed into this function. Wrapping an if statement around the processing correctly handles this while still performing correctly. --- src/raven.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/raven.js b/src/raven.js index b099d2a7dfbc..14c49ebde8c3 100644 --- a/src/raven.js +++ b/src/raven.js @@ -644,12 +644,14 @@ function joinRegExp(patterns) { // Be mad. var sources = [], i = patterns.length; while (i--) { - sources[i] = isString(patterns[i]) ? - // If it's a string, we need to escape it - // Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions - patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") : - // If it's a regexp already, we want to extract the source - patterns[i].source; + if (typeof patterns[i] != "undefined" && patterns[i]) { + sources[i] = isString(patterns[i]) ? + // If it's a string, we need to escape it + // Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions + patterns[i].replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1") : + // If it's a regexp already, we want to extract the source + patterns[i].source; + } } return new RegExp(sources.join('|'), 'i'); } From e75467de73490bc3681d1972d9fb2805d55b159d Mon Sep 17 00:00:00 2001 From: John Bacon Date: Fri, 10 Jan 2014 19:31:32 -0500 Subject: [PATCH 2/3] Test whether joinRegExp processes empty or undefined variables Raven throws an error if empty or undefined variables are processed by joinRegExp. Some browsers (such as Internet Explorer 8 and possibly earlier) apparently pass these variables, causing errors. --- test/raven.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/raven.test.js b/test/raven.test.js index 67c605ff7408..14736ffad69c 100644 --- a/test/raven.test.js +++ b/test/raven.test.js @@ -873,6 +873,12 @@ describe('globals', function() { 'a', 'b', 'a.b', /d/, /[0-9]/ ]).source, 'a|b|a\\.b|d|[0-9]'); }); + + it('should not process empty or undefined variables', function() { + assert.equal(joinRegExp([ + 'a', 'b', null, undefined + ]).source, 'a|b'); + }); }); }); From fdac9de77ccb95a509a2b7ff134ed5d3d18adf00 Mon Sep 17 00:00:00 2001 From: John Bacon Date: Fri, 10 Jan 2014 19:32:58 -0500 Subject: [PATCH 3/3] Use the isUndefined helper rather than typeof in joinRegExp --- src/raven.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raven.js b/src/raven.js index 14c49ebde8c3..7a2f79474ddb 100644 --- a/src/raven.js +++ b/src/raven.js @@ -644,7 +644,7 @@ function joinRegExp(patterns) { // Be mad. var sources = [], i = patterns.length; while (i--) { - if (typeof patterns[i] != "undefined" && patterns[i]) { + if (!isUndefined(patterns[i]) && patterns[i]) { sources[i] = isString(patterns[i]) ? // If it's a string, we need to escape it // Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions