Fixed Route Filter for link with special characters

xfrocks

Well-known member
Configure Route Filter as below and it doesn't work.

Screen Shot 2014-02-18 at 8.48.57 PM.webp

(I know, I know, the route is an add-on route but route filter should work with all kind of routes right?)

I have track down the issues and problem lies in XenForo_Link::translateRouteFilterToRegex. This method does not perform urldecode for the target route ($to variable). I added this simple line before the return statement and everything works as expected.

PHP:
$to = urldecode($to);

Actually there are 2 approaches to fix this issue. The above is the first one. Another is to require admin to enter "tags/blah(space)blah(space)blah/" in "Find Route" and perform urlencode when build links. I prefer the first approach because it seems to use less server resources.
 
I'm not clear what the issue is. A simple test case calling XenForo_Link::buildPublicLink() directly would be preferred.

If I do:
Code:
echo XenForo_Link::buildPublicLink('tags/blah+blah/');
The link is translated correctly.

Now, if the URL being generated is actually "tags/blah blah/", I think that's an issue with the URL generation code you're using as it should be doing the necessary urlencode()'ing.

I do see an issue with incoming conversions if your "replace with" has a "+" in it as they're urldecode()'d already.
 
Last edited:
Outgoing conversion works as expected with the above route filter:

PHP:
echo XenForo_Link::buildPublicLink('tags/blah+blah/');

However, when user comes from blah/, the URL will be rewritten as tags/blah+blah/ which is incorrect.
For incoming conversion, it should become tabs/blah(space)blah/.

I hope it is clearer now.
 
Right, that was roughly what I was getting at with the last line in my previous comment. The change has to be done "live" when handling the incoming route (or in the cache) as outgoing routes need to be URL encoded to be valid.

The ideal would probably be to have the filtering done before URL decoding, but that's applies to a much bigger range of code. Doing the urldecode on the from/to on incoming route filters seems to work.
 
Top Bottom