in reply to Re: Semicolons in webforms
in thread Semicolons in webforms

I'm using CGI and a package that my company has written. When data is received by the perl webservice I assign it to a string variable. For example:
# $srv is an instantiation of my companies package my %args = $srv->Vars(); # strxmltext is a string variable sent by the webserver and will conta +in a semicolon my $stringvariabe = $args{strxmltext};

Replies are listed 'Best First'.
Re^3: Semicolons in webforms
by dsheroh (Monsignor) on Dec 30, 2007 at 16:41 UTC
    OK, if I understand correctly, the semicolon would have already been changed to a newline within those few lines of code, right? If the client is a normal web browser, I'd say it's probably a bug in $srv's package. If not, then the client is most likely failing to encode its data properly before sending it. Either way, if the semicolons are already changed by the first time you see the data, you're not going to be able to change them to pipe characters to prevent it.

    If you have control of the client, running a tr/;/|/ over the data ($data =~ tr/;/|/;) before sending it will change the semicolons to pipes as you initially requested, but fixing the encoding and/or your company's package would be the better solution.

Re^3: Semicolons in webforms
by graff (Chancellor) on Dec 30, 2007 at 16:46 UTC
    # strxmltext is a string variable sent by the webserver and will conta +in a semicolon my $stringvariabe = $args{strxmltext};
    So, if "$stringvariabe" contains a value like "item1;bottle", and you want to "parse" that, do you mean that you want to split on semicolon to get a "name, value" pair -- like this?
    my ( $name, $value ) = split /;/, $stringvariabe;
    If you sometimes get three or more strings separated by semicolons, you probably want to assign the result of split to an array:
    my @strings = split /;/, $stringvariabe;
    Is there something more complicated about the task that you haven't mentioned yet?
      Unfortunately I don't have any control over the client. The problem is that the client is intentionally sending the semicolon as a delimiter (its written in C#). The other issue is the xml string could be a very large xml string with many semicolons. Ideally, I'd be able to simply replace the semicolons with pipes. I'm not really looking to do name value pairs since I need to do further processing of the XML before I handled the data that is delimited with semicolons. Any other advise? Here is another example if this is helpful:
      # this line represents the xml that I would receive from a client. $xmlstring = '<listofitems> <item> <itemid>1234</itemid> <itemname>genericname</itemname> <tablefield>1234;id</tablefield> </item> <item> <itemid>1235></itemid> <itemname>genericname2</itemname> <tablefield>1235;id</tablefield> <tablefield>1;specialtiem</tablefield> </item> </listofitems>';
      In my program I would then parse the xml data into other variables. The problem is that when I attempt to parse the data the semicolon in the tablefield xml tag screws it up. TIA.
        The client may use the semicolon as some kind of internal separator for the XML data, but if the data goes through a HTTP-GET or urlencoded HTTP-POST request, then it must be properly escaped.