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.
Comment | File | Size | Author |
---|---|---|---|
#6 | views-preg_grep_unknown_modifier-2694365-6.patch | 754 bytes | aubjr_drupal |
| |||
#3 | views-preg_grep_unknown_modifier-2694365-3.patch | 732 bytes | joelstein |
#2 | preg_grep_unknown_modifier-2694365-2.patch | 732 bytes | labboy0276 |
Comments
Comment #2
labboy0276 CreditAttribution: labboy0276 commentedComment #3
joelstein CreditAttribution: joelstein commentedThis works great! Except that there was a typo in the patch (a minus '-' instead of an equal sign '=').
Here's an updated patch.
Comment #4
labboy0276 CreditAttribution: labboy0276 commentedoops, not sure how I did that, thanks.
Comment #6
aubjr_drupal CreditAttribution: aubjr_drupal commentedUpdated this patch after running into this odd error. Matches Views v3.23 for D7.
Comment #7
aubjr_drupal CreditAttribution: aubjr_drupal commentedI should add that I've used this patch and it resolved my issue.
Comment #8
BrankoC CreditAttribution: BrankoC as a volunteer commentedHow do I reproduce the problem?
Comment #9
aubjr_drupal CreditAttribution: aubjr_drupal commentedviews_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.
Comment #10
BrankoC CreditAttribution: BrankoC as a volunteer commentedI 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:
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
?