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

The perl form is outputting missing space between names.

User inputs Los Angeles
it outputs: LosAngeles

User inputs John Doe
it outputs: JohnDoe

What is causing the problem? What's the fix for it? I need the space in between the two words.

thanks in advance

Replies are listed 'Best First'.
Re: Perl form user input
by marto (Cardinal) on Jun 10, 2019 at 05:58 UTC
      I'm not sure where to look for the problem.
      <div class="form-row"> <div class="col-md-6 mb-3"> <label for="city"><span class="text-danger p-1" style="font-size:18 +px"><b>*</b></span>City</label> <input type="text" name="city" class="form-control" id="city" place +holder="City" required> </div> ----------------------------------- <b>Name:</b> <input type="text" size="35" name="name"> <b>Address:</b> <input type="text" size="35" name="address"> <b>Town/City:</b> <input type="text" size="35" name="city"> <b>County/State:</b> <input type="text" size="35" name="state"> <b>Post/Zip:</b> <input type="text" size="35" name="zip"> <b>Country:</b> <input type="text" size="35" name="country"> <b>Email:</b> <input type="text" size="35" name="email"> ---------------------------------
      $message .= "<ul><li>Name:$FORM{'name'}<br>\n"; $message .= "<li>Address: $FORM{'address'}<br>\n"; $message .= "<li>City: $FORM{'city'}, $FORM{'state'}\. $FORM{' +zip'}<br>\n"; $message .= "<li>Country: $FORM{'country'}<br>\n"; $message .= "<li>Email: $FORM{'email'}<br>\n"; $message .= "<li>Phone $FORM{'phone'}<br>\n";
      ---------------------------------------------------------------
      $message .= "--"." $address\n"; $message .= "--"." $city, $state\. $zip\n"; $message .= "--"." $country\n"; $message .= "--"." $phone\n"; $message .= "--"." $email\n";
        ..where to look for the problem

        In the perl code (which you have not shown) that builds the %Form hash and other variables.

        poj
Re: Perl form user input
by FreeBeerReekingMonk (Deacon) on Jun 10, 2019 at 09:38 UTC
    Try to find the "untaint" function in the code, I suspect that there is a regexp that is s/[^A-Za-z0-9]//g removing all "weird" characters, and that includes the space.
      Could this sub be doing it? (i notice "remove any spaces")
      ############################# Subroutines ########################### ### PARSE SUBROUTINE sub parse_formx { local ($name, $value, $pair, $buffer, @pairs); if ($ENV{'REQUEST_METHOD'} eq 'GET') { # Split the name-value pairs @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { # Clear buffer and Get the input $buffer = ""; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); }else { &error("Bad request method, Use POST or GET"); exit; } #determine name and variable for each pair foreach $pair (@pairs) { # Split into name and value. ($name, $value) = split(/=/, $pair); # Ignore The Submit Button if($name =~ /submit/i) { next; } $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; + + + # Remove Any Possible System Shell Commands Or SSI's Etc. $name =~ s/~!/ ~!/g; $name =~ s/<!--(.|\n)*-->//g; $value =~ s/~!/ ~!/g; $value =~ s/<!--(.|\n)*-->//g; $value =~ s/^\s+//gms; # remove any leading spaces $value =~ s/\s+$//gms; # remove any trailing spaces $value =~ s/\s{2,}/ /gms; # remove any 2 spaces and put o +nly 1 $value =~ s/\|//g; # removes any Intruder tamperin +g $value =~ s/~//g; $value =~ s/\`//g; # removes any server side inclu +des $value =~ s/\~//g; # removes any server side inclu +des $value =~ s/\"//g; # removes quotes $value =~ s/\;//g; # removes html $value =~ s/\<//g; # removes html $value =~ s/\>//g; # removes html $value =~ s/\s+//g; # remove any spaces $value =~ s/^[\s]+|[\s]+$//gm; # remove any spaces $FORM{$name} = $value; } return %FORM; } # end of sub
        $value =~ s/\s+//g; # remove any spaces

        This is the line that is removing all whitespace from the values. You could probably comment it out (put a # at the beginning of the line), although that will affect all form values.

        As I said, this is a very old style of Perl CGI. I would strongly recommend a security audit and, at least at some point, an overhaul.

        Maybe? Please use code tags!!!
Re: Perl form user input
by LanX (Saint) on Jun 10, 2019 at 15:32 UTC
    Oh James ...please edit your posts.

    We like them stirred with <code> tags, not shaken! ;-)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: Perl form user input
by Anonymous Monk on Jun 10, 2019 at 06:01 UTC
    You are trying to trim the input from surrounding whitespace, not doing it wrong.
      s/not/but/