www.webdeveloper.com
Results 1 to 3 of 3

Thread: Passing a javascript 'escaped()' string

  1. #1
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132

    Question Passing a javascript 'escaped()' string

    I'm passing a javascript 'escaped()' string to a CGI script via the QUERY_STRING.
    This works as long as I don't use 'strict' but when I do I get this error

    ....can't use global $1

    $ENV{'QUERY_STRING'} = "n%26d+a%20l%24"; # test result to be "n&d+a l$"
    my $data = $ENV{'QUERY_STRING'};
    my $data =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C',hex($1))/eg;
    print "$data\n";

    Is there a simple soultion?

  2. #2
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    You are declaring $data with my twice.

    And just a note to simplify the regex. Since you know the two characters following a % are hex digits, there's no reason for the character classes, and pack('C', ...) can be more simply replaced with chr.
    Code:
    $data =~ s/%(..)/chr hex $1/eg;
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132
    Dah!!!
    And thanks for the tip on the simplification

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles