mozilla/rhino — pull request #18 by msmhrt (2011-10-29 04:19:49+00:00)
Title: Fixed issue with /\ca/ and doesn't match to string "\u0001"

The regex /\ca/ and /[\ca]/ should match to string "\u0001" , but it does not match.
I believe this patch can fix this issue.

without this patch:

js> escape("\u0001".match(/\ca/))
null
js> escape("\u0001".match(/[\ca]/))
Exception in thread "main" java.lang.RuntimeException
at org.mozilla.javascript.regexp.NativeRegExp.addCharacterToCharSet(NativeRegExp.java:1423)
at org.mozilla.javascript.regexp.NativeRegExp.processCharSetImpl(NativeRegExp.java:1636)
at org.mozilla.javascript.regexp.NativeRegExp.processCharSet(NativeRegExp.java:1460)
at org.mozilla.javascript.regexp.NativeRegExp.classMatcher(NativeRegExp.java:1658)
at org.mozilla.javascript.regexp.NativeRegExp.executeREBytecode(NativeRegExp.java:1901)
at org.mozilla.javascript.regexp.NativeRegExp.matchRegExp(NativeRegExp.java:2250)
at org.mozilla.javascript.regexp.NativeRegExp.executeRegExp(NativeRegExp.java:2277)
at org.mozilla.javascript.regexp.RegExpImpl.matchOrReplace(RegExpImpl.java:190)
at org.mozilla.javascript.regexp.RegExpImpl.action(RegExpImpl.java:74)
at org.mozilla.javascript.NativeString.execIdCall(NativeString.java:389)
at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:129)
at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
at org.mozilla.javascript.gen._stdin__2._c_script_0(Unknown Source)
at org.mozilla.javascript.gen._stdin__2.call(Unknown Source)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3156)
at org.mozilla.javascript.gen._stdin__2.call(Unknown Source)
at org.mozilla.javascript.gen._stdin__2.exec(Unknown Source)
at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:650)
at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:464)
at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:214)
at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:133)
at org.mozilla.javascript.Context.call(Context.java:521)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:536)
at org.mozilla.javascript.tools.shell.Main.exec(Main.java:197)
at org.mozilla.javascript.tools.shell.Main.main(Main.java:173)

js> "\\c_".match(/[\c_]/g)
Exception in thread "main" java.lang.RuntimeException
at org.mozilla.javascript.regexp.NativeRegExp.addCharacterToCharSet(NativeRegExp.java:1423)
at org.mozilla.javascript.regexp.NativeRegExp.processCharSetImpl(NativeRegExp.java:1636)
at org.mozilla.javascript.regexp.NativeRegExp.processCharSet(NativeRegExp.java:1460)
at org.mozilla.javascript.regexp.NativeRegExp.classMatcher(NativeRegExp.java:1658)
at org.mozilla.javascript.regexp.NativeRegExp.executeREBytecode(NativeRegExp.java:1901)
at org.mozilla.javascript.regexp.NativeRegExp.matchRegExp(NativeRegExp.java:2250)
at org.mozilla.javascript.regexp.NativeRegExp.executeRegExp(NativeRegExp.java:2277)
at org.mozilla.javascript.regexp.RegExpImpl.matchOrReplace(RegExpImpl.java:169)
at org.mozilla.javascript.regexp.RegExpImpl.action(RegExpImpl.java:74)
at org.mozilla.javascript.NativeString.execIdCall(NativeString.java:389)
at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:129)
at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
at org.mozilla.javascript.gen._stdin__1._c_script_0(Unknown Source)
at org.mozilla.javascript.gen._stdin__1.call(Unknown Source)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3156)
at org.mozilla.javascript.gen._stdin__1.call(Unknown Source)
at org.mozilla.javascript.gen._stdin__1.exec(Unknown Source)
at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:650)
at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:464)
at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:214)
at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:133)
at org.mozilla.javascript.Context.call(Context.java:521)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:536)
at org.mozilla.javascript.tools.shell.Main.exec(Main.java:197)
at org.mozilla.javascript.tools.shell.Main.main(Main.java:173)

with this patch:

js> escape("\u0001".match(/\ca/))
%01
js> escape("\u0001".match(/[\ca]/))
%01
js> "\\c_".match(/[\c_]/g)
\,c,_
js>