Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null character breaks regex patterns #10592

Open
5 of 6 tasks
tobil4sk opened this issue Feb 15, 2022 · 1 comment
Open
5 of 6 tasks

Null character breaks regex patterns #10592

tobil4sk opened this issue Feb 15, 2022 · 1 comment
Assignees
Milestone

Comments

@tobil4sk
Copy link
Member

tobil4sk commented Feb 15, 2022

When a regex pattern created directly using the constructor that contains a null character, it does not match properly on Eval, Neko, C++, lua, and Hashlink. PHP throws an error on the first match call due of the null character (Null byte in regex).

final containingNull = new EReg("abc\x00def", "");

trace(containingNull.match("abc")); // true, should be false
trace(containingNull.match("abc\x00def")); // true
trace(containingNull.match("abc\x00fed")); // true, should be false

On all other targets it works as expected.

On the other hand, the following works fine on (almost) all targets, where we use the regex literal syntax.

final containingNull = ~/abc\x00def/;

trace(containingNull.match("abc")); // false
trace(containingNull.match("abc\x00def")); // true (apart from on hashlink)
trace(containingNull.match("abc\x00fed")); // false

Targets affected:

tobil4sk added a commit to tobil4sk/neko that referenced this issue Feb 15, 2022
e.g. `new EReg("abc\x00def", "")` would erroneously match "abc"

HaxeFoundation/haxe#10592
Simn added a commit to HaxeFoundation/neko that referenced this issue Feb 16, 2022
* [regex] Update pcre to pcre2

* [regex] Throw if accessing match after match error

* [regex] Prevent null character breaking patterns

e.g. `new EReg("abc\x00def", "")` would erroneously match "abc"

HaxeFoundation/haxe#10592

* [regex] Add TODO regarding pcre2_substitute

* [cmake] Fix static Apache build

We can no longer link pcre as we use pcre2

* [cmake] Fix windows pcre static build

* [cmake] Download old PCRE for Apache

* [cmake] Remove unused flag for pcre windows build

* [cmake] Reenable PCRE_STATIC cmake flag for Win

* [cmake] Use https for pcre download for Apache

Co-authored-by: Simon Krajewski <simon@haxe.org>
@tobil4sk
Copy link
Member Author

The Php issue is a Php bug so I think it's fine to leave it. There is already way to avoid the bug by escaping it or by using Haxe's regex literal syntax, which escapes it automatically.

On Hashlink it is a little bit more complicated however, as according to this page: https://haxe.org/manual/std-String-encoding.html, Hashlink does not support null bytes, so I'm not sure whether it makes sense or not to fix this there. Also, it would potentially require a change of the Hashlink api to pass in the length of the pattern into the constructor.

@Simn Simn added this to the Later milestone Mar 24, 2023
@Simn Simn modified the milestones: Later, Release 4.3 Mar 25, 2023
@Simn Simn self-assigned this Mar 30, 2023
@Simn Simn modified the milestones: Release 4.3, Later Mar 30, 2023
andyli pushed a commit to HaxeFoundation/neko that referenced this issue Jul 4, 2023
* [regex] Update pcre to pcre2

* [regex] Throw if accessing match after match error

* [regex] Prevent null character breaking patterns

e.g. `new EReg("abc\x00def", "")` would erroneously match "abc"

HaxeFoundation/haxe#10592

* [regex] Add TODO regarding pcre2_substitute

* [cmake] Fix static Apache build

We can no longer link pcre as we use pcre2

* [cmake] Fix windows pcre static build

* [cmake] Download old PCRE for Apache

* [cmake] Remove unused flag for pcre windows build

* [cmake] Reenable PCRE_STATIC cmake flag for Win

* [cmake] Use https for pcre download for Apache

Co-authored-by: Simon Krajewski <simon@haxe.org>
# Conflicts:
#	Earthfile
#	README.md
#	extra/azure-pipelines/Brewfile-STATIC_DEPS_NONE
#	libs/CMakeLists.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants