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/web/interfaces/default/js/javascript-global-functions.js

    r32893 r33043  
    1111{
    1212    return $("#" + id.replace(/\./g, "\\.").replace(/:/g,"\\:"));
     13}
     14
     15// Debugging function to print a string's non-basic chars in hex
     16// Based on https://stackoverflow.com/questions/36637146/javascript-encode-string-to-hex/36637293
     17// https://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex
     18gs.functions.string2hex = function(str) {
     19    var hex, i;
     20
     21    var result = "";
     22    for (i=0; i<str.length; i++) {
     23        charcode = str.charCodeAt(i);
     24        // ASCII table: https://cdn.sparkfun.com/assets/home_page_posts/2/1/2/1/ascii_table_black.png
     25        // 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)
     26        if(charcode < 20 || charcode > 126) { //doesn't work: if(str.charAt(i) < ' ' || str.charAt(i) > '~') {
     27            hex = charcode.toString(16);
     28            result += "x" + ("000"+hex).slice(-4);
     29        }
     30        else {
     31            result += str.charAt(i);
     32        }
     33    }
     34
     35    return result;
    1336}
    1437
Note: See TracChangeset for help on using the changeset viewer.