Changeset 2426


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

Location:
trunk/gsdl/src/recpt
Files:
3 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
  • trunk/gsdl/src/recpt/cgiutils.h

    r1285 r2426  
    3939void split_cgi_args (const cgiargsinfoclass &argsinfo, text_t argstr,
    4040             cgiargsclass &args);
     41
     42text_t encode_commas (const text_t &intext);
     43text_t decode_commas (const text_t &intext);
    4144
    4245// turns any '-' in a cgi argument into "(-)"
  • trunk/gsdl/src/recpt/collectoraction.cpp

    r2418 r2426  
    4141#include "nullproto.h"
    4242#include "argdb.h"
     43#include "cgiutils.h"
    4344
    4445#if !defined (__WIN32__)
     
    856857
    857858  text_tarray inputvalues;
    858   // this relies on filenames/URLs not being able to contain
    859   // commas
    860859  splitchar (inputarglist.begin(), inputarglist.end(), ',', inputvalues);
    861860  // remove any empty values from the end of the array
     
    906905    rv += "<input type=text name=\"bc1input\" value=\"";
    907906    if (i < numvalues) {
    908       rv += dm_safe(inputvalues[i]);
     907      rv += dm_safe(decode_commas(inputvalues[i]));
    909908    }
    910909    rv += "\" size=50>";
    911910    if (badsources) {
    912911      if ((i < numvalues) && (!inputvalues[i].empty())) {
    913     if (failedsources[inputvalues[i]] == "1") {
     912    if (failedsources[decode_commas(inputvalues[i])] == "1") {
    914913      rv += "_iconcross_";
    915914    } else {
     
    16421641
    16431642  text_tarray inputvalues, inputtypes;
    1644   // this relies on filenames/URLs not being able to contain commas
    16451643  splitchar (args["bc1input"].begin(), args["bc1input"].end(), ',', inputvalues);
    16461644  splitchar (args["bc1inputtype"].begin(), args["bc1inputtype"].end(), ',', inputtypes);
     
    16511649      text_t type = "file://"; // default
    16521650      if (i < numtypes) type = inputtypes[i];
    1653       options += " -download \"" + type + format_url(inputvalues[i]) + "\"";
     1651      options += " -download \"" + type + format_url(decode_commas(inputvalues[i])) + "\"";
    16541652    }
    16551653  }
     
    18521850
    18531851  text_tarray inputvalues;
    1854   // this relies on filenames/URLs not being able to contain
    1855   // commas
    1856   char *tmp = args["bc1input"].getcstr();
    18571852  splitchar (args["bc1input"].begin(), args["bc1input"].end(), ',', inputvalues);
    18581853
     
    18641859
    18651860  for (int i = 0; i < numvalues; i++) {
    1866     text_t value = format_url(inputvalues[i]);
     1861    text_t value = format_url(decode_commas(inputvalues[i]));
    18671862    text_t type = "file://"; // default
    18681863    if (!value.empty()) {
     
    18751870      if (type == "file://") {
    18761871    if (!file_exists(value) && !directory_exists(value)) {
    1877       failedsources[inputvalues[i]] = "1";
     1872      failedsources[decode_commas(inputvalues[i])] = "1";
    18781873      badsources = true;
    18791874    }
    18801875      } else if (type == "http://") {
    18811876    if (gsdl_system ("perl -S ping.pl -quiet http://" + value, true, logout)) {
    1882       failedsources[inputvalues[i]] = "1";
     1877      failedsources[decode_commas(inputvalues[i])] = "1";
    18831878      badsources = true;
    18841879    }
    18851880      } else if (type == "ftp://") {
    18861881    if (gsdl_system ("perl -S ping.pl -quiet ftp://" + value, true, logout)) {
    1887       failedsources[inputvalues[i]] = "1";
     1882      failedsources[decode_commas(inputvalues[i])] = "1";
    18881883      badsources = true;
    18891884    }
Note: See TracChangeset for help on using the changeset viewer.