There's no need for DrupalAPCCache::escapeStringForRegex(), regex has it handled.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

twistor’s picture

Status: Active » Needs review
FileSize
1.34 KB

Let's kill a couple function calls.

R.Muilwijk’s picture

Status: Needs review » Fixed

Committed to dev.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

MaskOta’s picture

Status: Closed (fixed) » Needs work

Sorry 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.

A----’s picture

Same 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, …).

A----’s picture

davidsickmiller’s picture

Status: Needs work » Needs review
davidsickmiller’s picture

Assigned: twistor » Unassigned

This probably doesn't need to be assigned to the original reporter.