diff --git a/src/renderers/dom/__tests__/ReactDOMProduction-test.js b/src/renderers/dom/__tests__/ReactDOMProduction-test.js index ee46261d4f0ef..ce80989c2eeb8 100644 --- a/src/renderers/dom/__tests__/ReactDOMProduction-test.js +++ b/src/renderers/dom/__tests__/ReactDOMProduction-test.js @@ -96,7 +96,9 @@ describe('ReactDOMProduction', function() { var container = document.createElement('div'); ReactDOM.render(, container); }).toThrowError( - /React: production error #109\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=109&args=%22Component%22&stack=%22Error.*reactProdInvariant.*%22 for more details\./ // eslint-disable-line max-len + 'React: production error #109. Visit ' + + 'http://facebook.github.io/react/docs/error-codes.html?invariant=109&args[]=Component' + + ' for more details.' ); }); }); diff --git a/src/shared/utils/__tests__/reactProdInvariant-test.js b/src/shared/utils/__tests__/reactProdInvariant-test.js index accefc0bd947b..2dd797bbcde9d 100644 --- a/src/shared/utils/__tests__/reactProdInvariant-test.js +++ b/src/shared/utils/__tests__/reactProdInvariant-test.js @@ -8,7 +8,6 @@ * * @emails react-core */ -/* eslint-disable max-len */ 'use strict'; var reactProdInvariant; @@ -23,19 +22,25 @@ describe('reactProdInvariant', function() { expect(function() { reactProdInvariant(124, 'foo', 'bar'); }).toThrowError( - /React: production error #124\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=124&args=%22foo%22&args=%22bar%22&stack=%22Error.*reactProdInvariant.*%22 for more details\./ + 'React: production error #124. Visit ' + + 'http://facebook.github.io/react/docs/error-codes.html?invariant=124&args[]=foo&args[]=bar' + + ' for more details.' ); expect(function() { reactProdInvariant(20); }).toThrowError( - /React: production error #20\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=20&stack=%22Error.*reactProdInvariant.*%22 for more details\./ + 'React: production error #20. Visit ' + + 'http://facebook.github.io/react/docs/error-codes.html?invariant=20' + + ' for more details.' ); expect(function() { - reactProdInvariant(77, 'foo', 'bar', 'and', 'what', 'else'); + reactProdInvariant(77, '
', '&?bar'); }).toThrowError( - /React: production error #77\. Visit http:\/\/facebook\.github\.io\/react\/docs\/error-codes\.html\?invariant=77&args=%22foo%22&args=%22bar%22&args=%22and%22&args=%22what%22&args=%22else%22&stack=%22Error.*reactProdInvariant.*%22 for more details\./ + 'React: production error #77. Visit ' + + 'http://facebook.github.io/react/docs/error-codes.html?invariant=77&args[]=%3Cdiv%3E&args[]=%26%3Fbar' + + ' for more details.' ); }); }); diff --git a/src/shared/utils/reactProdInvariant.js b/src/shared/utils/reactProdInvariant.js index 1136f03b21411..4bc893545063d 100644 --- a/src/shared/utils/reactProdInvariant.js +++ b/src/shared/utils/reactProdInvariant.js @@ -18,31 +18,23 @@ */ function reactProdInvariant(code, a, b, c, d, e, f) { var argCount = arguments.length - 1; - var error = new Error(''); - var format = ( + var message = ( 'React: production error #' + code + '. ' + 'Visit http://facebook.github.io/react/docs/' + 'error-codes.html?invariant=' + code ); - while (argCount > 0) { - format += '&args=%22%s%22'; - argCount--; + for (var argIdx = 0; argIdx < argCount; argIdx++) { + message += '&args[]=' + encodeURIComponent(arguments[argIdx + 1]); } - format += '&stack=%22' + (error.stack ? encodeURIComponent(error.stack) : '') + '%22'; - format += ' for more details.'; - - var args = [a, b, c, d, e, f]; - var argIndex = 0; - error.message = format.replace(/%s/g, function() { - return args[argIndex++]; - }); + message += ' for more details.'; + var error = new Error(message); error.name = 'Invariant Violation'; - error.framesToPop = 1; // we don't care about reactProdInvariant's own frame + throw error; }