Changeset 33111


Ignore:
Timestamp:
2019-05-27T20:50:23+12:00 (5 years ago)
Author:
ak19
Message:

GS309RC1 had a bug when doc editing a meta like ex.Title that contained a semi-colon. The final commits for rc1 that would URLEncode CGI param values in Java passed into perl, encoded the entirety of each paramvalue. This solved the initial problem of taking care of special chars like the degree symbol. But the extra URL encoding introduced a new problem: characters like the semi-colon, meaningful in URLs, were already encoded and would end up with another layer of encoding which perl wouldn't know to double-decode, so that the requested prevMetaValue would not match and new meta set to replace old would always accumulate instead of replace again. I think Dr Bainbridge had already mentioned the solution initially, when he discussed how to take care of special chars: URL encode just char values over 128. Except I didn't understand the relevance then, so I didn't think of it in the initial solution. When I reinvented the solution to resolve the 2nd problem, what he had earlier said was the full solution to the first problem finally made sense.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2Construct.java

    r33051 r33111  
    897897    private String urlEncodeValue(String paramName, String paramVal) {
    898898        String oldParamVal = paramVal;
     899        paramVal = "";
    899900        try{
    900             paramVal = URLEncoder.encode(paramVal, "UTF-8");           
    901             // Better way as per https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
    902             // but our release kits' Java is too old for importing java.nio.charset.StandardCharsets
    903             //paramVal = URLEncoder.encode(paramVal, StandardCharsets.UTF_8.name());           
     901            // don't do this, as it will double encode semicolons (and other such regular chars that will get URL encoded).
     902            // But then perl won't double-decode to get original semicolon back.
     903            // paramVal += URLEncoder.encode(oldParamVal, "UTF-8");
     904
     905            // Instead, just encode chars whose int value is >= 128
     906            for(int i = 0; i < oldParamVal.length(); i++) {
     907            char c = oldParamVal.charAt(i);
     908            if(c >= 128) {
     909                paramVal += URLEncoder.encode(""+c, "UTF-8");
     910                // Better way as per https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
     911                // but our release kits' Java is too old for importing java.nio.charset.StandardCharsets
     912                //paramVal = URLEncoder.encode(""+c, StandardCharsets.UTF_8.name());       
     913            } else {
     914                paramVal += c;
     915            }
     916            }
     917       
     918            //logger.error("@@@@@@@@ old paramVal is: |" + oldParamVal + "|");
     919            //logger.error("@@@@@@@@ new param val for paramName " + paramName + " is: |" + paramVal + "|");
     920           
    904921        } catch(UnsupportedEncodingException uee) {
    905922            logger.warn("**** Unable to encode query_string param " + paramName + " in UTF-8, so attempting to continue with its unencoded value."); // don't output param value to log, in case of sensitive data?
Note: See TracChangeset for help on using the changeset viewer.