Ignore:
Timestamp:
2019-04-17T20:26:03+12:00 (5 years ago)
Author:
ak19
Message:

Getting facet searching working again in tomcat 8, where it had broken due to reserved and unsafe chars in the URL. The fix required using the recent makeURLSafe() and makeURLComponentSafe() methods in facet-scripts.js. This meant that these functions and their helper functions needed to be moved into their own script file, newly introducing utility_scripts.js, rather than remain in document_scripts.js since doc_scripts.js is not included on the query.xsl page which includes facet-scripts.js

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/facet-scripts.js

    r32110 r33016  
    2121    }
    2222   
    23     var countsString = "s1.facetQueries=&";
     23    var countsString = "s1.facetQueries=";
    2424    if(counts.length > 0)
    2525    {
    26         countsString = "s1.facetQueries=[";
    27         var countsStringBuffer = "";
     26        var countsStringBuffer = "[";
    2827        for(var i = 0; i < counts.length; i++)
    2928        {
    3029            // escape any apostrophes in facet query terms
    3130            // (ext/solr's Greenstone3SearchHandler does the other half of handling them)
    32             countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\"";
     31            //countsStringBuffer += "\"" + encodeURI(counts[i]).replace(/'/g, "%2527") + "\"";
     32            // calling makeURLSafe() here will ensure percent signs are escaped away too
     33            // by the end of makeURLComponentSafe() call below
     34            countsStringBuffer += "\"" + makeURLSafe(counts[i]).replace(/'/g, "%2527") + "\"";
    3335            if(i < counts.length - 1)
    3436            {
     
    3739        }
    3840       
    39         countsString += encodeURI(countsStringBuffer) + "]&";
     41        countsStringBuffer += "]";
     42
     43        // We need to ensure that the *value* of s1.facetQueries (so everything after
     44        // s1.facetQueries= and before the connecting &) are safe, which requires escaping,
     45        // and are further also escaped to not be mistaken for their reserved meaning.
     46        // : is a reserved character in URLs, [] are unsafe characters. All need escaping.
     47        // So call makeURLComponentSafe(), not makeURLSafe()
     48        countsString = countsString + makeURLComponentSafe(countsStringBuffer, 1);
    4049    }
    4150   
    42     console.log("STRING IS " + countsString)
     51    countsString += "&";
     52    console.log("STRING IS " + countsString);
    4353   
    4454    $.ajax(gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/search/" + gs.cgiParams.s + "?" + searchString + countsString + "excerptid=resultsArea")
Note: See TracChangeset for help on using the changeset viewer.