Both in Actionscript3 and Javascript these statements give the same result:
/\S/.test(null) => true
/null/.test(null) => true
/m/.test(null) => false
/n/.test(null) => true
Seems that null value is converted into string “null” in this case.
Is this a known bug in Ecmascript or am I missing something?
It’s not a bug, but you are right,
nullcoerces to'null'and that behavior is defined on the spec:RegExp.prototype.test(string), internally is equivalent to the expression:RegExp.prototype.exec(string) != nullexecmethod type converts the first argument to string, using theToStringinternal operation (look the Step 1 of theexecmethod).ToStringinternal operation, explicitly returns"null"when the input is oftype
Null.In conclusion, in your examples, the RegExp matchs against the string
'null', so the first non-space character, in this case the letter'n'.