0

I am using perl and CGI,where i am accumulating data and placing it in url.Like below

http://acv.farm.com/devpm/tiber/tiyu.cgi?sid=233&region=Asia&description=for data in 'bf' and 'cx'&psite=bothwork.

Here in this url in description their is single quotes if it comes, then my button is not working. If we remove single codes manually then button is working.

I am taking this url in one variable my $durl=http://acv.farm.com/devpm/tiber/tiyu.cgi?sid=$id&region=$reg&description=$desc&psite=$pwork

also i am formatting this with $durl =~ s/\+/\%2B/g

And then I am passing this variable in href like this <a href=\"$durl\">

I am looking for the logic to handle single and double quotes if it comes in url.

kasli
  • 29
  • 6
  • I got the solution i am using %27 to encode for quotes.Thanks – kasli Jun 01 '21 at 10:01
  • 3
    No no no, that wasn't the solution I was suggesting. Use [`URI::Escape`](https://metacpan.org/pod/URI::Escape) or [`URI`](https://metacpan.org/pod/URI), instead of manually escape _some_ characters (as suggested in the answers of the question I linked). – Dada Jun 01 '21 at 11:59

1 Answers1

0
use URI qw( );

my $durl = URI->new('http://acv.farm.com/devpm/tiber/tiyu.cgi');
$durl->query_form(
   sid         => $id,
   region      => $reg,
   description => $desc,
   psite       => $pwork,
);

# Force stringification. Not needed if you're treating it as a string.
$durl = $durl->as_string;
   -or-
$durl = "$durl";
ikegami
  • 367,544
  • 15
  • 269
  • 518