Changeset 33051 for main


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

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/GS2PerlConstructor.java

    r33046 r33051  
    2020import java.io.InputStream;
    2121import java.io.IOException;
    22 //import java.io.UnsupportedEncodingException;
    23 //import java.net.URLEncoder;
    24 //import java.nio.charset.StandardCharsets;
    2522import java.util.ArrayList;
    2623import java.util.Vector;
     
    334331        // http://www.cgi101.com/class/ch3/text.html
    335332       
    336         // 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),
    337         // URL encode the query_string, as at https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
    338        
    339         // perl/CGI.pm doesn't like us URL encoding the entire query string such as the equal sign between each paramName and paramValue.
    340         // So we URL encode each paramValue separately, which is done in GS2Construct.java::runCommand()
    341         /*
    342         String old_query_string = this.query_string;
    343         try{
    344             this.query_string = URLEncoder.encode(this.query_string, StandardCharsets.UTF_8.name());
    345             //this.query_string = this.query_string.replace("+","%2B"); // https://stackoverflow.com/questions/1211229/in-a-url-should-spaces-be-encoded-using-20-or
    346         } catch(UnsupportedEncodingException uee) {
    347             logger.warn("**** Unable to encode query_string in UTF-8, so attempting to continue with the unencoded value of query_string");
    348             this.query_string = old_query_string;
    349         }
    350         */
     333        // And since we need to ensure that special characters won't get clobbered on Windows by perl/CGI.pm
     334        // (see https://www.nntp.perl.org/group/perl.perl5.porters/2016/10/msg240120.html),
     335        // each param *value* in QUERY_STRING, not QUERY_STRING in entirety, is further URL encoded,
     336        // as at https://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters
     337        // This URL encoding of paramValues already happened in GS2Construct.java::runCommand(), so QUERY_STRING is ready now.
    351338       
    352339        String[] envvars = {
  • 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.