Loading ...
Sorry, an error occurred while loading the content.

3037Re: ampersand and friends

Expand Messages
  • Eric Amick
    Oct 3 3:06 AM
      On 3 Oct 2003 08:52:54 -0000, you wrote:

      >I've got a JWSDP-1.2 backend running
      >a JAXRPC service that exposes a WSDL.
      >I've got a frontend that uses PERL to
      >generate web pages and SOAP::Lite
      >to connect to the back end.
      >Most of the time everything is fine. Once
      >in a while, somebody types in an
      >ampersand and blows something up.
      >I've isolated the problem down to what
      >appears to be an issue with encoding, but
      >I'm not sure. I have written a little program
      >that deterministically causes a fault
      >to occur. You can imagine that
      >in my "real code" the only thing that is
      >difference is that I am basically taking
      >input from the user, checking it for
      >some basic stuff and then putting it
      >into the function where below you see
      >hardcoded strings.
      >#!/usr/bin/perl -w
      >use strict;
      >use SOAP::Lite;
      >use Data::Dumper;
      >my $abc = SOAP::Lite->service("");
      ># this one works
      >@results = $abc->myfunc($token, 'Soccer');
      > print Dumper(@results);
      ># this one does not work
      >@results = $abc->myfunc($token, 'a & b');
      > print Dumper(@results);

      XML doesn't care for ampersands (and a couple of other characters) in its
      data. The HTML::Entities module should be useful:

      use HTML::Entities;
      . . .

      # Encode "&", "<", ">", and "'"
      encode_entities($input_string, "&<>'");

      $input_string is modified in place by the encode_entities function by
      default. For more details, consult the module documentation.

      Eric Amick
      Columbia, MD
    • Show all 6 messages in this topic