@@ -46,7 +46,7 @@ var flatten = function (array) {
4646 * // => ['Emphasize all phone numbers like ', <strong>884-555-4443</strong>, '.'
4747 *
4848 * @param {string } str
49- * @param {regexp |str } match Must contain a matching group
49+ * @param {RegExp |str } match Must contain a matching group
5050 * @param {function } fn
5151 * @return {array }
5252 */
@@ -70,6 +70,12 @@ function replaceString(str, match, fn) {
7070
7171 // Apply fn to all odd elements
7272 for ( var i = 1 , length = result . length ; i < length ; i += 2 ) {
73+ /** @see {@link https://github.com/iansinnott/react-string-replace/issues/74 } */
74+ if ( result [ i ] === undefined || result [ i - 1 ] === undefined ) {
75+ console . warn ( 'reactStringReplace: Encountered undefined value during string replacement. Your RegExp may not be working the way you expect.' ) ;
76+ continue ;
77+ }
78+ 7379 curCharLen = result [ i ] . length ;
7480 curCharStart += result [ i - 1 ] . length ;
7581 result [ i ] = fn ( result [ i ] , i , curCharStart ) ;
0 commit comments