CGI::Untaint::url - validate a URL


CGI-Untaint-url documentation Contained in the CGI-Untaint-url distribution.

Index


Code Index:

NAME

Top

CGI::Untaint::url - validate a URL

SYNOPSIS

Top

  use CGI::Untaint;
  my $handler = CGI::Untaint->new($q->Vars);

  my $url = $handler->extract(-as_url => 'web_address');

DESCRIPTION

Top

is_valid

This Input Handler verifies that it is dealing with a reasonable URL. This mostly means that it will find the first thing that looks like a URL in your input, where by "looks like", we mean anything that URI::URL thinks is sensible, (with some tweaks, courtesy of URI::Find::Schemeless::Stricter), so it will accept any of (for example):

  http://c2.com/cgi/wiki
  www.tmtm.com
  See: http://www.redmeat.com/redmeat/1996-09-30/
  [http://www.angelfire.com/la/carlosmay/Tof.html]
  ftp://ftp.ftp.org/

The resulting value will be a URI::URL object.

SEE ALSO

Top

URI::URL. URI::Find::Schemeless::Stricter.

AUTHOR

Top

Tony Bowden

BUGS and QUERIES

Top

Please direct all correspondence regarding this module to: bug-CGI-Untaint-url@rt.cpan.org

COPYRIGHT

Top


CGI-Untaint-url documentation Contained in the CGI-Untaint-url distribution.

package CGI::Untaint::url;

$VERSION = '1.00';

use strict;
use base 'CGI::Untaint::printable';
use URI::Find::Schemeless::Stricter;

sub is_valid {
	my $self = shift;
	my $value = $self->value or die "No value\n";
	my @urls;
	our $finder = URI::Find::Schemeless::Stricter->new(
		sub {
			push @urls, shift;
		}
	);
	$finder->find(\$value);
	return $self->value($urls[0]) if @urls;
	return;
}

1;