Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There's no need for DrupalAPCCache::escapeStringForRegex(), regex has it handled.
Comment | File | Size | Author |
---|---|---|---|
#7 | 0001-Issue-2183285-by-A-Use-Q.-E-for-regex-literals.patch | 1.39 KB | A---- |
#1 | apc-regex-literal-2183285-1.patch | 1.34 KB | twistor |
Comments
Comment #1
twistor CreditAttribution: twistor commentedLet's kill a couple function calls.
Comment #2
R.Muilwijk CreditAttribution: R.Muilwijk commentedCommitted to dev.
Comment #5
MaskOta CreditAttribution: MaskOta commentedSorry to open an old issue but i am having problem with this regex expression.
Basicly whenever there is a '/' in the expression it doesn't escape it like it should.
I understand that \Q .. \E should take all characters in the regex literally / included but it just doesn't seem to work.
If i have a / i get "APCIterator::__construct(): Unknown modifier 'f'" where f is the first character after the /
and drupal shows "Fatal error: APCIterator::__construct(): Could not compile regular expression: /^\Qv_site::cache::theme_registry/foo/bar\E/"
I am runing apcu 4.0.2 on a ubuntu 14.04 virtual box.
Comment #6
A---- CreditAttribution: A---- commentedSame as MaskOta. That patch should never have been commited in the first place.
First,
\Q…\E
escapes regular expression metacharacters, not delimiters. Meaning$
,[
and the like. See http://php.net/manual/en/regexp.reference.meta.php .Also, that means you trust user input. It's in a protected method but heh. There are tons of things that can make this go boo-boo.
$str = '\Eunescaped string\Q'; […] new APCIterator('user', '/^\Q'.$str.'\E/');
.Finally, there's only one good way of quoting user input in a regexp, the accurately named
preg_quote($str, $delimiter)
. While/
is often used as a delimiter, through mere ignorance, it's often inconvenient and can be switched to another one, hence the second parameter. See http://php.net/manual/en/regexp.reference.delimiters.php . The\Q…\E
is here for practical reasons (readability, …).Comment #7
A---- CreditAttribution: A---- commentedComment #8
davidsickmiller CreditAttribution: davidsickmiller commentedStackoverflow agrees: https://stackoverflow.com/a/20520551/718475
Comment #9
davidsickmiller CreditAttribution: davidsickmiller commentedThis probably doesn't need to be assigned to the original reporter.