Changeset 33112 for main

Show
Ignore:
Timestamp:
27.05.2019 21:07:15 (5 months ago)
Author:
ak19
Message:

Related to previous commit. Using StringBuffer? for more optimal concatenation, since I can't remember whether it was Java or JavaScript? that optimised String concatenation, or even whether at least one of them ever did so.

Files:
1 modified

Legend:

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

    r33111 r33112  
    896896 
    897897    private String urlEncodeValue(String paramName, String paramVal) { 
    898         String oldParamVal = paramVal; 
    899         paramVal = ""; 
     898        StringBuffer modParamVal = new StringBuffer(); 
    900899        try{ 
    901900            // don't do this, as it will double encode semicolons (and other such regular chars that will get URL encoded). 
     
    904903 
    905904            // Instead, just encode chars whose int value is >= 128 
    906             for(int i = 0; i < oldParamVal.length(); i++) { 
    907             char c = oldParamVal.charAt(i); 
     905            for(int i = 0; i < paramVal.length(); i++) { 
     906            char c = paramVal.charAt(i); 
    908907            if(c >= 128) { 
    909                 paramVal += URLEncoder.encode(""+c, "UTF-8"); 
     908                modParamVal.append(URLEncoder.encode(""+c, "UTF-8")); 
    910909                // Better way as per https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters 
    911910                // but our release kits' Java is too old for importing java.nio.charset.StandardCharsets 
    912911                //paramVal = URLEncoder.encode(""+c, StandardCharsets.UTF_8.name());         
    913912            } else { 
    914                 paramVal += c; 
     913                modParamVal.append(c); 
    915914            } 
    916915            } 
    917          
    918             //logger.error("@@@@@@@@ old paramVal is: |" + oldParamVal + "|"); 
     916 
     917            //logger.error("@@@@@@@@ old paramVal for paramName " + paramName + "is: |" + paramVal + "|"); 
     918            paramVal = modParamVal.toString(); 
    919919            //logger.error("@@@@@@@@ new param val for paramName " + paramName + " is: |" + paramVal + "|"); 
    920920             
    921921        } catch(UnsupportedEncodingException uee) { 
    922922            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? 
    923             paramVal = oldParamVal;  
    924         } 
     923        } 
     924 
    925925        return paramVal; 
    926926    }