HaxeFoundation / HaxeFoundation/haxe
[js, flash] `^` anchor broken when using `EReg.matchSub()`
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
This example returns false (which is correct) on all targets apart from Javascript and Flash.
```haxe
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:
```haxe
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?
Contributor guide
Research direction
Start with the linked implementations in std/js/_std/EReg.hx and std/flash/_std/EReg.hx, then run the two Haxe reproductions from the issue across the affected targets. Compare the matchSub behavior with the other targets; done means the ^ reproduction behaves consistently, with the related $ behavior addressed or clearly scoped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100