Ignore:
Timestamp:
2019-04-30T18:33:42+12:00 (5 years ago)
Author:
ak19
Message:

Not a bugfix, but to help with encoding issues, including to help with current, still unresolved encoding issue. 1. Introduction of string2hex functions in JavaScript and Java. 2. Overriding GSXML.elemtToString() with introduction of additional debugEncoding parameter that will turn on string2hex use when printing request and response XMLs. Now non-basic ASCII characters in the XML will be printed in hex if debugEncoding parameter passed in is true. 3. The inactive Connector elements in server8.xml.svn now also have the attribute URIEncoding set to UTF-8. Some of these inactive Connectors get turned on at times, such as for https. In which case we will need tomcact to also interpret get/post data coming in through those connectors to be sent on as utf-8.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/util/Misc.java

    r32608 r33043  
    5656    }   
    5757    }
    58 
     58   
     59   
     60    // Debugging function to print a string's non-basic chars in hex
     61    // Based on https://stackoverflow.com/questions/923863/converting-a-string-to-hexadecimal-in-java
     62    public static String stringToHex(String str) {
     63      String result = "";
     64      for(int i = 0; i < str.length(); i++) {
     65            int charCode = str.codePointAt(i); // unicode codepoint / ASCII code
     66           
     67            // ASCII table: https://cdn.sparkfun.com/assets/home_page_posts/2/1/2/1/ascii_table_black.png
     68            // If the unicode character code pt is less than the ASCII code for space and greater than for tilda, let's display the char in hex (x0000 format)
     69            if((charCode >= 20 && charCode <= 126) || charCode == 9 || charCode == 10 || charCode == 13) { // space to tilda, TAB, LF, CR are printable
     70                result += str.charAt(i);
     71            } else {
     72                result += "x" + String.format("%04x", charCode);
     73            }
     74      }
     75     
     76      return result;
     77    }
     78   
     79   
    5980    public static void printHash(HashMap map) {
    6081    Set entries = map.entrySet();
Note: See TracChangeset for help on using the changeset viewer.