filter.js generates incorrect URL when “Use full friendly URLs” is enabled

Painbaker

Well-known member
Affected version
2.3.7
When using filter.js on the public interface with AJAX filtering and the “Use full friendly URLs” option enabled, the generated request URL is incorrect. It misses a ? before the query string, which results in an invalid URL.

/forum-search/&_xfFilter[text]=test&_xfFilter[prefix]=0?_xfResponseType=json&_xfWithData=1&_xfRequestUri=/&_xfToken=1752795635,ed211239fc7c29d2bfdacd66aecf7ca10

When expected

/forum-search/?_xfFilter[text]=test&_xfFilter[prefix]=0?_xfResponseType=json&_xfWithData=1&_xfRequestUri=/&_xfToken=1752795635,ed211239fc7c29d2bfdacd66aecf7ca10


In filter.js, the URL is built by concatenating parameters using + '&' + params, regardless of whether the base AJAX URL contains a query string or not:


Code:
    _filterAjax (text, prefix)
        {
            //  
            if (!text.length)
            {
                this._clearAjaxRows()
                const matched = this._applyFilter(this._getSearchRows(), text, prefix)
                this._toggleNoResults(matched == 0)
            }
            else
            {
                const params = Object.entries({
                    text,
                    prefix: prefix ? 1 : 0,
                }).map(([key, value]) => `_xfFilter[${key}]=${encodeURIComponent(value)}`).join('&')

                const ajaxUrl = this.options.ajax + '&' + params // <--
                //
            }
        },
 
Last edited:
Back
Top Bottom