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

User Agents: OPAWG regexes unicode usage must be adjusted #1537

Open
eteubert opened this issue Nov 21, 2024 · 0 comments
Open

User Agents: OPAWG regexes unicode usage must be adjusted #1537

eteubert opened this issue Nov 21, 2024 · 0 comments
Labels

Comments

@eteubert
Copy link
Member

Some regexes contain unicode characters, like this one: "^Podcast\u2019ler\/.*\\(.*\\)"

That results in an error:

php > echo preg_match("/^Podcast\u2019ler\/.*\\(.*\\)/", "Podcast’ler/1 (2)");

Warning: preg_match(): Compilation failed: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u at offset 10 in php shell code on line 1

The regexes must be converted to be PCRE2 compatible:

php > echo preg_match("/^Podcast\x{2019}ler\/.*\\(.*\\)/u", "Podcast’ler/1 (2)");
1
  1. convert \u2019 to \x{2019} (or any other unicode reference)
  2. append the u modifier at the end

Fix should probably be applied around here

foreach ($item->user_agents as $regex) {
$compiled_regex = str_replace('/', '\/', $regex);
if (preg_match("/{$compiled_regex}/", $user_agent_string) === 1) {
return $item;
}
}
where the regexes are "compiled".

@eteubert eteubert added the bug label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant