Open
Description
> /(a)?\1/.exec("")
Array [ "", undefined ]
> /(a)?\1/.exec("a")
Array [ "", undefined ]
> /(a)?\1/.exec("aa")
Array [ "aa", "a" ]
~Firefox
But in libc++, the equivalent operations return null
, null
and [ "aa", "a" ]
. The spec is unambiguous; https://262.ecma-international.org/5.1/#sec-15.10.2.9 5.3 says unmatched backreferences should match the empty string.
Full example: https://godbolt.org/z/ndrqej718 (libstdc++ has the same bug)
Found in this battery of tests - most or all of the libc++ failures are this, #133314, or both.