You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Joshua Chamas <jo...@chamas.com> on 2001/07/10 21:09:17 UTC

Re: [IDEA] Automatic URL Encoding

Philip Mak wrote:
> 
> Is it practical/efficient for Apache::ASP to automatically scan <A HREF>
> tags?
> 
> I had an idea about an automatic URL Encoding option. The idea is that
> someone types "PerlSetVar URLEncode 1" in their httpd.conf. Then,
> Apache::ASP will automatically call $Server->URLEncode() on every <A HREF>
> tag.
> 
> Applications that generate a lot of GET URLs would benefit from this, e.g.
> instead of:
> 
> <a href="program.asp?param1=<%=$Server->URLEncode($param1)%>&amp;param2=<%=$Server->URLEncode($param2)">
> 

Runtime parsing of content for something like this is very expensive.
For an example of how expensive, run a benchmark against an ASP 
page with SessionQueryParse turned on with sessions active, which 
splices session-id into URLs ( not just <a href=...> type too )

If this is a generally useful feature ( anyone else ? ) it may 
make sense to offer it as a config option as you suggest, and 
just do some runtime parsing, but I might otherwise recommend 
using XMLSubs for this.  Is there any precedent with other web
application platforms for this kind of functionality? 

Here's an example of how one might do this with XMLSubs

  PerlSetVar XMLSubsMatch a

in global.asa:

sub a { # something like this, untested
  my($args, $text) = @_;

  if(my $href = $args->{href}) {
    if($href =~ /\?/) {
	my($head,$tail) = split(/\?/, $href);
	my(@params) = split(/\&/, $tail);
	my @new_params;
	for my $param ( @params ) {
	  $param =~ s/\=(.*)/'='.$Server->URLEncode($1)/;
	  push(@new_params, $param);
	}
	$args->{href} = $head."?".join('&', @new_params);        
    }
  }

  print "<a ".join(' ', map { "$_=$args->{$_}" } keys %$args).">$text</a>"; 
}

-- Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks <- Web Link Checking          Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org