-
Notifications
You must be signed in to change notification settings - Fork 212
Add fix and tests for \x with no hex digits #478
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
Add fix and tests for \x with no hex digits #478
Conversation
I hadn't known about Perl's warning. Good point. I have merged and will edit the docs. |
Carlo asked which version of Perl does the warning - though I can't see his comment here - just his email. Looks like Perl is half baked:
It doesn't give a warning if \x is the last thing in the pattern. |
I found this helpful site: https://perlbanjo.com/bca01b0a27 The https://perlbanjo.com/394c21e056 The Finally, the trailing |
when "use warnings" is enabled, and it's forbidden when "use strict" | ||
is enabled. Because we don't have warnings, we simply forbid it. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment needs updating so it correctly states use re 'strict'
or even better had that part if removed as shown by:
diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c
index bdf2e8c..d5cd0c2 100644
--- a/src/pcre2_compile.c
+++ b/src/pcre2_compile.c
@@ -2192,8 +2192,8 @@ else
/* Perl has the surprising/broken behaviour that \x without following
hex digits is treated as an escape for NUL. Their source code laments
this but keeps it for backwards compatibility. A warning is printed
- when "use warnings" is enabled, and it's forbidden when "use strict"
- is enabled. Because we don't have warnings, we simply forbid it. */
+ when "use warnings" is enabled, Because we don't have warnings, we
+ simply forbid it. */
if (ptr >= ptrend || (cc = XDIGIT(*ptr)) == 0xff)
{
/* Not a hex digit */
I would provide a PR but will be easier if Philip just commits that directly IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh dear, didn't realize that the "strict" confusion was also reflected in the documentation.
To clarify, Perl also shows warnings when using less than two hexadecimal digits (ex:/\xa/
), and the warning we are referring to also apply to /\x/
, which is why it doesn't apply to it when it is the last thing in a pattern.
That is documented below, but in the case of the single digit hexadecimals we are ignoring those warnings for backward compatibility. On a side note they all become errors with use re 'strict'
as it is also described there.
Again, I am not arguing there should be any changes on behaviour to this code, just pointing out that there is some slight confusion on the rationale for doing them.
is still experimental though even in the unreleased version of Perl the comments in the code referred by mistake to "use strict" though, that doesn't have any effect. |
The |
I wasn't arguing that we shouldn't fix it, just got tripped by the comment typo and the fact that my test was also unlucky to have BTW thanks for the helpful site tip; |
Why mess around with something that's broken, and which no users are likely to want?
Grasp the nettle, and simply disallow
\x
with no following hex digits (following non-hex character, or at end of pattern).As documented in the code comments added, this diverges from Perl's default behaviour, but aligns with Perl+warnings, so is consistent with best-practices Perl usage.