Browse Source

testcase for a bug in String.prototype.replace() handling of empty captures and dollar replacements

pull/1/head
Sami Vaarala 12 years ago
parent
commit
1aa26b5aa2
  1. 26
      testcases/test-dev-bug-string-replace-undefined-cap.js

26
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);
}
Loading…
Cancel
Save