We have a client that puts # in their urls for various reasons. We were faced with a dilemma on what to do in this regard and it was easiest to offer more of a universal solution as we would get errors like:

preg_grep(): Unknown modifier 'o' views.module:415

This was due to the regex getting escaped early and views_menu_alter says nope, not gonna happen.

So I wrote a patch to make sure the # is not escaped on a regex call for all the things.

this is also mentioned here: https://www.drupal.org/node/1733464#comment-7633309

but his solution is for his currency issue, this addresses the problem universally.

Patch coming up.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

labboy0276 created an issue. See original summary.

labboy0276’s picture

joelstein’s picture

Status: Active » Reviewed & tested by the community
FileSize
732 bytes

This works great! Except that there was a typo in the patch (a minus '-' instead of an equal sign '=').

Here's an updated patch.

labboy0276’s picture

oops, not sure how I did that, thanks.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 3: views-preg_grep_unknown_modifier-2694365-3.patch, failed testing. View results

aubjr_drupal’s picture

Updated this patch after running into this odd error. Matches Views v3.23 for D7.

aubjr_drupal’s picture

Status: Needs work » Needs review

I should add that I've used this patch and it resolved my issue.

BrankoC’s picture

How do I reproduce the problem?

aubjr_drupal’s picture

Issue summary: View changes

views_menu_alter() looks like it's building a list of options based on field values. To ensure it doesn't have any duplicates when it generates that menu item, it runs preg_replace on it to manipulate it and avoid dupes. It must include field values, which would make any values with a pound sign in it bust up the preg_replace call.

In my client's site's case, it had a view that included content types with fields of type "link" that held URLs (in a classic field). A few of the URLs had # characters in them like the following:

http://www.starcityblog.com/2010/09/science-odyssey-as-courts-weigh-stat...

Whenever Views pulled in that field (type: link) The preg_replace saw the ....html#more, stopped the regex at the #, took the next character m to be a "multiple" flag for the regex. It then barfed on the next letter "o" because it is an invalid modifier.

I hope this helps. I can't help beyond that.

BrankoC’s picture

I am not able to reproduce #9. I sense I am missing a step (or reading over one) where the contents of the link field are being fed to Drupal's menu system.

I am able to reproduce the original issue:

  • Create a view
  • Call it let's say "Paths with Anchors"
  • "Create a page" for the view
  • Give it a path "paths-with-anchors#more"
  • Click Save & Exit
  • Admire the error messages:

Warning: preg_grep(): Unknown modifier 'o' in views_menu_alter() (line 475 of modules/views/views.module).
Warning: Invalid argument supplied for foreach() in views_menu_alter() (line 477 of modules/views/views.module).

The views_menu_alter() hook creates a regular expression (regex) per view page. In the case of the example, the path paths-with-anchors#more leads to a regex #^(paths-with-anchors#more)$# which, as aubjr_drupal says, breaks at the hash character of the fragment identifier.

The patch appears to solve this.

I am a little bit worried about adding anchors (or queries for that matter) to the path column of the menu_router table, but even if that were a bad idea (lots of people seem to think it is a good idea), this bug should still not exist.

The patch seems to fix the problem.

I am not too sure about using the variable name $parsed, that could mean anything. How about something like $safe_path?