Changeset 3151


Ignore:
Timestamp:
2002-06-17T15:27:27+12:00 (22 years ago)
Author:
jrm21
Message:

MSIE >= 6.0 encodes high bytes in URL as %uHHHH (unicode) rather than %HH%HH (utf8), apparently regardless of what character encoding is in use. We now convert that as well, although we assume we always convert it to utf8. This should really use whatever encoding the user interface is using...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/recpt/cgiutils.cpp

    r2426 r3151  
    2525
    2626#include "cgiutils.h"
    27 
     27#include "gsdlunicode.h"
    2828
    2929static unsigned short hexdigit (unsigned short c) {
     
    5757
    5858// convert %xx and + to their appropriate equivalents
     59// IE 6.0 and later use "%u" followed by 4 hex digits...
    5960void decode_cgi_arg (text_t &argstr) {
    6061  text_t::iterator in = argstr.begin();
     
    6768    else if (*in == '%') {
    6869      unsigned short c = '%';
    69       in++;
    70       if (in != end) {
    71     c = hexdigit (*in);
    72     in++;
     70      ++in;
     71      if (in != end) { // this is an encoding...
     72    if (*in == 'u') { // convert %uHHHH to unicode then current encoding
     73      // this assumes a short int is at least 16 bits...
     74      ++in; 
     75      if (in != end)
     76        c=hexdigit(*in++) << 12;
     77      if (in != end)
     78        c+=hexdigit(*in++) << 8;
     79      if (in != end)
     80        c+=hexdigit(*in++) << 4;
     81      if (in != end)
     82        c+=hexdigit(*in);
     83      /* BAD!! The following assumes the interface is using utf-8. But
     84         at this point we don't know what encoding we are using, unless
     85         we can parse it out of the string we are currently decoding... */
     86      text_t uni=" ";
     87      uni[0]=c;
     88      text_t utf8=to_utf8(uni);
     89      int last_byte=utf8.size()-1;
     90      for (int i=0;i<last_byte;i++)
     91        *out++ = utf8[i];
     92      c=utf8[last_byte];
     93    } else {  // convert %HH to hex value
     94      c = hexdigit (*in);
     95      ++in;
     96      if (in != end && c < 16) { // sanity check on the previous character
     97        c = c*16 + hexdigit (*in);
     98      }
     99    }
    73100      }
    74       if (in != end && c < 16) { // sanity check on the previous character
    75     c = c*16 + hexdigit (*in);
    76       }
    77      
    78101      *out = c;
    79102    } else *out = *in;
Note: See TracChangeset for help on using the changeset viewer.