Ignore:
Timestamp:
2001-05-16T15:38:12+12:00 (23 years ago)
Author:
sjboddie
Message:

added an ugly hack to prevent problems when multiple value arguments
contain commas - this should be fixed properly some day but for now
it'll do the trick

File:
1 edited

Legend:

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

    r2417 r2426  
    109109    // store this key=value pair
    110110    if (!key.empty()) {
    111       // if arg occurs multiple times (as is the case with
    112       // multiple checkboxes using the same name) we'll
    113       // create a comma separated list of all the values
    114       // (we should probably use some kind of array here to
    115       // avoid problems when values already contain commas)
     111
     112      // if arg occurs multiple times (as is the case with multiple
     113      // checkboxes using the same name) we'll create a comma separated
     114      // list of all the values (this uses a hack that encodes naturally
     115      // occurring commas as %2C - values will therefore need to be decoded
     116      // again before use) - it should use an array instead
    116117      const cgiarginfo *info = argsinfo.getarginfo (key);
    117118      if (info != NULL && info->multiplevalue) {
    118119    text_t newvalue = args[key];
    119120    if (args.lookupcgiarg(key).source == cgiarg_t::cgi_arg) newvalue += ",";
    120     newvalue += value;
     121    newvalue += encode_commas(value);
    121122    args.setarg (key, newvalue, cgiarg_t::cgi_arg);
    122123
     
    126127    }
    127128  }
     129}
     130
     131text_t encode_commas (const text_t &intext) {
     132
     133  text_t outtext;
     134
     135  text_t::const_iterator here = intext.begin ();
     136  text_t::const_iterator end = intext.end ();
     137
     138  while (here != end) {
     139    if (*here == ',') outtext += "%2C";
     140    else outtext.push_back (*here);
     141    here ++;
     142  }
     143  return outtext;
     144}
     145
     146text_t decode_commas (const text_t &intext) {
     147
     148  text_t outtext;
     149 
     150  text_t::const_iterator here = intext.begin ();
     151  text_t::const_iterator end = intext.end ();
     152 
     153  while (here != end) {
     154    if ((here+2<end) && *here == '%' && *(here+1) == '2' &&
     155    (*(here+2) == 'C' || *(here+2) == 'c')) {
     156      here += 2;
     157      outtext.push_back(',');
     158     
     159    }else outtext.push_back (*here);
     160    here ++;
     161  }
     162  return outtext;
    128163}
    129164
Note: See TracChangeset for help on using the changeset viewer.