Ignore:
Timestamp:
2019-05-06T16:23:43+12:00 (5 years ago)
Author:
ak19
Message:

Tweak to Friday's commit to URL encode param values: can't use nio.StandardCharsets because our release kit JDK is too old to recognise this import, so hardcoding UTF-8 charset name which is what people used to do in the past. Also updated comments. And removed some unnecessary commented out code from GS2PerlConstructor.java

File:
1 edited

Legend:

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

    r33045 r33051  
    2525import java.io.UnsupportedEncodingException;
    2626import java.net.URLEncoder;
    27 import java.nio.charset.StandardCharsets;
    2827import java.util.Collections;
    2928import java.util.Iterator;
     
    845844                String paramvalue = (String) entry.getValue();
    846845
    847                 // And need to ensure that special characters won't get clobbered on Windows by perl/CGI.pm (https://www.nntp.perl.org/group/perl.perl5.porters/2016/10/msg240120.html),
    848                 // URL encode the query_string, as at https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
    849        
    850                 // perl/CGI.pm doesn't like us URL encoding the entire query string such as the equal sign between each paramName and paramValue.
     846                // This will be used to set QUERY_STRING in the environment, see build/GS2PerlConstructor.java
     847                // Need to also ensure that special characters in param values won't get clobbered on Windows by perl/CGI.pm,
     848                // see also https://www.nntp.perl.org/group/perl.perl5.porters/2016/10/msg240120.html
     849                // Therefore URL encode CGI param values in the query_string, as at https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
     850       
     851                // perl/CGI.pm doesn't like us URL encoding the entire QUERY_STRING such as the equal sign between each paramName and paramValue.
    851852                // So we URL encode each paramValue separately, which is done in GS2Construct.java::runCommand()
    852853                querystring.append(paramname + "=" + urlEncodeValue(paramname, paramvalue));
     
    897898        String oldParamVal = paramVal;
    898899        try{
    899             paramVal = URLEncoder.encode(paramVal, StandardCharsets.UTF_8.name());         
     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());           
    900904        } catch(UnsupportedEncodingException uee) {
    901905            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.