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

\d does not work anymore since 0.2.7 #461

Closed
tobias47n9e opened this issue Mar 25, 2018 · 3 comments
Closed

\d does not work anymore since 0.2.7 #461

tobias47n9e opened this issue Mar 25, 2018 · 3 comments

Comments

@tobias47n9e
Copy link

Up until 0.2.6 (?P<user_agent>[a-zA-Z\d-_]+/[0-9\.]+) was a valid regex. Since 0.2.7 \d does not work and only (?P<user_agent>[a-zA-Z0-9-_]+/[0-9\.]+) works. Is it possible that that is a regression because as far as I understand RE2 it should be valid.

The issue was raised here:
https://gitlab.com/tobias47n9e/wikibase_rs/issues/1

@BurntSushi
Copy link
Member

BurntSushi commented Mar 25, 2018

Ug. That is definitely not an (intentionally, IIRC) valid regex, but it looks like the old parser accepted it anyway. The problem is that your syntax is attempting to write a character range, where the end of the range is _ but the beginning of the range is \d. Starting a range with a class itself isn't meaningful, so the parser today returns an error. In general, the - character is always interpreted as indicating a range unless it is escaped or unless it appears at the beginning or end of a character class. e.g., While [\d-_] is invalid, [\d_-] is valid and does what you want.

At the very least, the error message could be better here and should call out the fact that it's trying to interpret a range.

Note that it is also possible that the current behavior is actually undesirable and we might want to be a bit more flexible in allowing - to be treated as a literal - if either end of its range isn't actually a valid start or end of a range.

@BurntSushi
Copy link
Member

@tobias47n9e Also, note that \d isn't actually [0-9]. It is much bigger than that, and accepts any codepoint in the \p{Digit} Unicode property.

@tobias47n9e
Copy link
Author

Oh. That makes a lot of sense 😄 Not sure what most people except from the single dash (literal or range). Stricter interpreting with a more helpful error message does sound good to me.

About the 2nd comment: Not sure if I even need \d at the moment because I am just trying to restrict the types of user agents people use. I can always expand it when people complain 😄

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