tame1 has asked for the wisdom of the Perl Monks concerning the following question:

Here's a strange one (and one which will probably make
Lincoln S. wanna rip me a new one).

I am making a web page which passes just one field to a perl script -
a textarea field with multiple lines.
Then that data is fed line by line to a GD.pm based script which
should make an image from the text - but (and here's where we
manage to bring in yet another lstein module) the CGI.pm alters
the basic structure of the text in the text field such that, when
the data gets to the GD calls (parsed via CGI's param) GD will
balk after just the first character (or space).

Manually hitting the script with the url like
http://my.site.org/script.pl?text=I+Like+Ike works fine. But
passing that text via a form does NOT.

Are we having fun yet?

What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"

Replies are listed 'Best First'.
Re: CGI parsing difficulty
by snax (Hermit) on Nov 21, 2000 at 13:12 UTC
    Have you compared what the strings look like (before passing them to GD) using the two calling methods (form submission vs. URL explicit definition)?

    I.e. good old fashioned print statement debugging?

    It seems there would have to be a difference in the strings for GD to be able to handle one and not the other.

Re: CGI parsing difficulty
by extremely (Priest) on Nov 21, 2000 at 15:07 UTC
    As a quick check, try stripping out freaky characters, like NULL.  $text =~ tr/\030-\176//cd or something similar... Maybe you are handing it a unicode string? A scad of NULLS would make it pretty unhappy I'd guess.

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: CGI parsing difficulty
by wardk (Deacon) on Nov 21, 2000 at 19:29 UTC
    the CGI.pm alters the basic structure of the text in the text field

    By "basic structure" does this mean that the textarea box text is formatted in some manner within the textarea? (for instance, pasting in text from a word processor or spreadsheet, or using a specific font?). If this is the case, then you have possibly some rogue characters (like "bullets") and will need to strip them/replace them as extremely pointed out.

    Providing perhaps a snippet of the offending code would be helpful.

Re: CGI parsing difficulty
by geektron (Curate) on Nov 22, 2000 at 00:39 UTC
    probably because spaces are going to be translated into %20 in the HTTP request -- it's not CGI.pm 'messing with' anything, it's part of HTTP.

    if it works hitting the script 'manually', maybe you need to check your line-parsing. if you're trying to split on the + sign, you're probably not getting any parsing.

    that said, i think we need a code snippet to further offer assistance.

      OK - the form is just a single field, a textarea field.
      I type in multiple lines, seperated by :: (for now)

      Here is the code that is troublesome in the target script:

      my $text = $query->param("text"); make_image($text); exit(0); ########################################################## # Make an image from the lines in the array # sub make_image { my $text = shift; my @lines = split(/\n/,$text); my $counter = 80; foreach my $line (@lines) { $im->stringTTF($black, "/home/httpd/html/ribbon.ttf", 15, 0, 5 +0, 80,$line); if ($@) { $im->string(gdSmallFont, 50, 150, "$@", $black); die "Cannot print!$!\n"; } $counter += 10; } binmode STDOUT; print $query->header(-type=>'image/png'); print $im->png; }
      This code has been altered a million times, so if you find some syntax error, it's probably something I haven't fixed from the last edit ;-)

      Anyhow, if I hit http://localhost/myscript.pl?text=I+LOVE+MY+WIFE then it works. Going through a web form which then writes <img src="/myscript.pl?$text"> ($text being pulled by $text = $q->param("text") ) then it only prints the first letter, the I.

      My goal here is to eventually make a script that people can type in their text, the thing makes a multi-line image from it with that nice ribbon font, and the result gets sent as a kind of greeting card/invitation (for weddings, child birth announcements, etc).

      Any help would be appreciated.

      What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"
        Anyhow, if I hit http://localhost/myscript.pl?text=I+LOVE+MY+WIFE then it works. Going through a web form which then writes <img src="/myscript.pl?$text"> ($text being pulled by $text = $q->param("text") ) then it only prints the first letter, the I.
        You are properly URI-escaping the code you print in $text, right? You can't just do this:
        print qq{<img src="/myscript.pl?$text">};
        because you need to re-percentify or plusify spaces, etc etc., as in:
        use URI; my $uri = URI->new("/myscript.pl"); $uri->query($text); my $uri_string = $uri->as_string; print qq{<img src="$uri_string">};

        -- Randal L. Schwartz, Perl hacker