From 86b44349dec8db499935927260821cdee211ece4 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Sun, 6 Dec 2015 13:46:16 -0800 Subject: [PATCH] Avoid negative lookahead in regular expression I'm trying to use React with otto (https://github.com/robertkrimen/otto), which is implemented in Go and does not support lookaheads or backreferences in regular expressions. (Unfortunately that *does* mean that otto isn't fully compatible with the ECMA5 spec; but since this is the only lookahead I am aware of in the React codebase, this change makes React once again compatible with otto, and any other JS implementation that may not be fully compliant on regular expressions). As far as I can tell, the previous code replaced a sequence of slash characters with one more slash than before. The new code avoids the negative lookahead by matching any sequence of slash characters and then using the special `$&` placeholder to replace the matched sequence with the original sequence, plus one more slash. --- src/isomorphic/children/ReactChildren.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/isomorphic/children/ReactChildren.js b/src/isomorphic/children/ReactChildren.js index 836ac15c5b..e23fca1c75 100644 --- a/src/isomorphic/children/ReactChildren.js +++ b/src/isomorphic/children/ReactChildren.js @@ -21,9 +21,9 @@ var twoArgumentPooler = PooledClass.twoArgumentPooler; var fourArgumentPooler = PooledClass.fourArgumentPooler; -var userProvidedKeyEscapeRegex = /\/(?!\/)/g; +var userProvidedKeyEscapeRegex = /\/+/g; function escapeUserProvidedKey(text) { - return ('' + text).replace(userProvidedKeyEscapeRegex, '//'); + return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/'); }