Fixed unrecognized expression error in xenforo.js

Gia Bảo

Member
Goto this url:
http://xenforo.com/community/forums/bugs/#/xyz/0
=>
Uncaught Error: Syntax error, unrecognized expression: #/xyz/0

This error is throw in xenforo.js:

Code:
$(window).on('load', function() {
    if (isScrolled || !window.location.hash)
    {
        return;
    }
    var hash = window.location.hash.replace(/[:.#\s\[\]]/g, ''),
        $match = $('#' + hash); //error here
    if ($match.length)
    {
         $match.get(0).scrollIntoView(true);
    }
});

I know this error is harmless. But it's better to be fixed.

Of course this error will be thrown if we add a hash like #/xyz/0 to every forum url (in my custom route prefix too)
 
Fixed - I changed from trying to strip invalid characters to whitelisting alphanumeric, underscore and dash.
 
Back
Top Bottom