haxe icon indicating copy to clipboard operation
haxe copied to clipboard

[js, flash] `^` anchor broken when using `EReg.matchSub()`

Open tobil4sk opened this issue 3 years ago • 0 comments

This example returns false (which is correct) on all targets apart from Javascript and Flash.

function main() {
    trace(~/^/.matchSub("1 ", 1));
}

A similar issue was opened on the neko repository, however, the issue is with the Javascript implementation and not that one. HaxeFoundation/neko#164

This is because in both cases it has to be hand-implemented (mentioning flash as well here because the implementation is identical): https://github.com/HaxeFoundation/haxe/blob/8410d24d9369bbf7358a1d51a195ceae7c7d0624/std/js/_std/EReg.hx#L70-L71 https://github.com/HaxeFoundation/haxe/blob/8410d24d9369bbf7358a1d51a195ceae7c7d0624/std/flash/_std/EReg.hx#L72

As a bonus, this returns true everywhere:

function main() {
    trace(~/$/.matchSub("1 ", 0, 1));
}

I'm not sure we can do much about this as it's linked to the way the pcre library works (the length given is assumed to be the entire length of the string), but I guess if we were to fix ^ for Javascript and Flash, we might as well fix $ on these targets too?

tobil4sk avatar Feb 27 '22 09:02 tobil4sk