diff --git a/testcases/test-dev-bug-string-replace-undefined-cap.js b/testcases/test-dev-bug-string-replace-undefined-cap.js new file mode 100644 index 00000000..57b46952 --- /dev/null +++ b/testcases/test-dev-bug-string-replace-undefined-cap.js @@ -0,0 +1,26 @@ + +/*=== +foo +foo +fo +fo +f +f +===*/ + +/* Undefined captures were not skipped correctly. */ + +try { + print('foo'.replace(/(o)|(o)/, '$1')); + print('foo'.replace(/(o)|(o)/, '$01')); + + // capture 2 not found, matching string should be replaced with empty; + // with the bug, the first one would print "f2o". + print('foo'.replace(/(o)|(o)/, '$2')); + print('foo'.replace(/(o)|(o)/, '$02')); + print('foo'.replace(/(o)|(o)/g, '$2')); + print('foo'.replace(/(o)|(o)/g, '$02')); +} catch (e) { + print(e); +} +