.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Data::Validate::URI 3pm" .TH Data::Validate::URI 3pm "2017-08-26" "perl v5.26.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Data::Validate::URI \- common url validation methods .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Data::Validate::URI qw(is_uri); \& \& if(is_uri($suspect)){ \& print "Looks like an URI\en"; \& } else { \& print "Not a URI\en"; \& } \& \& # or as an object \& my $v = Data::Validate::URI\->new(); \& \& die "not a URI" unless ($v\->is_uri(\*(Aqfoo\*(Aq)); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module collects common \s-1URI\s0 validation routines to make input validation, and untainting easier and more readable. .PP All functions return an untainted value if the test passes, and undef if it fails. This means that you should always check for a defined status explicitly. Don't assume the return will be true. .PP The value to test is always the first (and often only) argument. .PP There are a number of other \s-1URI\s0 validation modules out there as well (see below.) This one focuses on being fast, lightweight, and relatively 'real\-world'. i.e. it's good if you want to check user input, and don't need to parse out the \s-1URI/URL\s0 into chunks. .PP Right now the module focuses on \s-1HTTP\s0 URIs, since they're arguably the most common. If you have a specialized scheme you'd like to have supported, let me know. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .IP "\fBnew\fR \- constructor for \s-1OO\s0 usage" 4 .IX Item "new - constructor for OO usage" .Vb 1 \& new(%options); .Ve .RS 4 .IP "\fIDescription\fR" 4 .IX Item "Description" Returns a Data::Validator::URI object. This lets you access all the validator function calls as methods without importing them into your namespace or using the clumsy \&\fIData::Validate::URI::function_name()\fR format. .IP "\fIArguments\fR" 4 .IX Item "Arguments" .RS 4 .PD 0 .ie n .IP "%options" 4 .el .IP "\f(CW%options\fR" 4 .IX Item "%options" .PD Options to be passed into the underlying Data::Validate::Domain module .RE .RS 4 .RE .IP "\fIReturns\fR" 4 .IX Item "Returns" Returns a Data::Validate::URI object .RE .RS 4 .RE .IP "\fBis_uri\fR \- is the value a well-formed uri?" 4 .IX Item "is_uri - is the value a well-formed uri?" .Vb 1 \& is_uri($value); .Ve .RS 4 .IP "\fIDescription\fR" 4 .IX Item "Description" Returns the untainted \s-1URI\s0 if the test value appears to be well-formed. Note that you may really want one of the more practical methods like is_http_uri or is_https_uri, since the \s-1URI\s0 standard (\s-1RFC 3986\s0) allows a lot of things you probably don't want. .IP "\fIArguments\fR" 4 .IX Item "Arguments" .RS 4 .PD 0 .ie n .IP "$value" 4 .el .IP "\f(CW$value\fR" 4 .IX Item "$value" .PD The potential \s-1URI\s0 to test. .RE .RS 4 .RE .IP "\fIReturns\fR" 4 .IX Item "Returns" Returns the untainted \s-1URI\s0 on success, undef on failure. .IP "\fINotes, Exceptions, & Bugs\fR" 4 .IX Item "Notes, Exceptions, & Bugs" This function does not make any attempt to check whether the \s-1URI\s0 is accessible or 'makes sense' in any meaningful way. It just checks that it is formatted correctly. .RE .RS 4 .RE .IP "\fBis_http_uri\fR \- is the value a well-formed \s-1HTTP\s0 uri?" 4 .IX Item "is_http_uri - is the value a well-formed HTTP uri?" .Vb 1 \& is_http_uri($value, \e%options); .Ve .RS 4 .IP "\fIDescription\fR" 4 .IX Item "Description" Specialized version of \fIis_uri()\fR that only likes http:// urls. As a result, it can also do a much more thorough job validating. Also, unlike \fIis_uri()\fR it is more concerned with only allowing real-world URIs through. Things like relative hostnames are allowed by the standards, but probably aren't wise. Conversely, null paths aren't allowed per \s-1RFC 2616\s0 (should be '/' instead), but are allowed by this function. .Sp This function only works for fully-qualified URIs. /bob.html won't work. See \s-1RFC 3986\s0 for the appropriate method to turn a relative \s-1URI\s0 into an absolute one given its context. .Sp Returns the untainted \s-1URI\s0 if the test value appears to be well-formed. .Sp Note that you probably want to either call this in combo with \fIis_https_uri()\fR. i.e. .Sp print \*(L"Good\*(R" if(is_http_uri($uri) || is_https_uri($uri)); .Sp or use the convenience method is_web_uri which is equivalent and faster, because it does the work only once. .IP "\fIArguments\fR" 4 .IX Item "Arguments" .RS 4 .PD 0 .ie n .IP "$value" 4 .el .IP "\f(CW$value\fR" 4 .IX Item "$value" .PD The potential \s-1URI\s0 to test. .IP "\e%options" 4 .IX Item "%options" Options to be passed into the underlying Data::Validate::Domain module. If called as a method, the options are ignored. .RE .RS 4 .RE .IP "\fIReturns\fR" 4 .IX Item "Returns" Returns the untainted \s-1URI\s0 on success, undef on failure. .IP "\fINotes, Exceptions, & Bugs\fR" 4 .IX Item "Notes, Exceptions, & Bugs" This function does not make any attempt to check whether the \s-1URI\s0 is accessible or 'makes sense' in any meaningful way. It just checks that it is formatted correctly. .RE .RS 4 .RE .IP "\fBis_https_uri\fR \- is the value a well-formed \s-1HTTPS\s0 uri?" 4 .IX Item "is_https_uri - is the value a well-formed HTTPS uri?" .Vb 1 \& is_https_uri($value. \e%options); .Ve .RS 4 .IP "\fIDescription\fR" 4 .IX Item "Description" See \fIis_http_uri()\fR for details. This version only likes the https \s-1URI\s0 scheme. Otherwise it's identical to \fIis_http_uri()\fR .IP "\fIArguments\fR" 4 .IX Item "Arguments" .RS 4 .PD 0 .ie n .IP "$value" 4 .el .IP "\f(CW$value\fR" 4 .IX Item "$value" .PD The potential \s-1URI\s0 to test. .IP "\e%options" 4 .IX Item "%options" Options to be passed into the underlying Data::Validate::Domain module. If called as a method, the options are ignored. .RE .RS 4 .RE .IP "\fIReturns\fR" 4 .IX Item "Returns" Returns the untainted \s-1URI\s0 on success, undef on failure. .IP "\fINotes, Exceptions, & Bugs\fR" 4 .IX Item "Notes, Exceptions, & Bugs" This function does not make any attempt to check whether the \s-1URI\s0 is accessible or 'makes sense' in any meaningful way. It just checks that it is formatted correctly. .RE .RS 4 .RE .IP "\fBis_web_uri\fR \- is the value a well-formed \s-1HTTP\s0 or \s-1HTTPS\s0 uri?" 4 .IX Item "is_web_uri - is the value a well-formed HTTP or HTTPS uri?" .Vb 1 \& is_web_uri($value, \e%options); .Ve .RS 4 .IP "\fIDescription\fR" 4 .IX Item "Description" This is just a convinience method that combines is_http_uri and is_https_uri to accept most common real-world URLs. But it's faster, because it does the work only once. .IP "\fIArguments\fR" 4 .IX Item "Arguments" .RS 4 .PD 0 .ie n .IP "$value" 4 .el .IP "\f(CW$value\fR" 4 .IX Item "$value" .PD The potential \s-1URI\s0 to test. .IP "\e%options" 4 .IX Item "%options" Options to be passed into the underlying Data::Validate::Domain module. If called as a method, the options are ignored. .RE .RS 4 .RE .IP "\fIReturns\fR" 4 .IX Item "Returns" Returns the untainted \s-1URI\s0 on success, undef on failure. .IP "\fINotes, Exceptions, & Bugs\fR" 4 .IX Item "Notes, Exceptions, & Bugs" This function does not make any attempt to check whether the \s-1URI\s0 is accessible or 'makes sense' in any meaningful way. It just checks that it is formatted correctly. .RE .RS 4 .RE .IP "\fBis_tel_uri\fR \- is the value a well-formed telephone uri?" 4 .IX Item "is_tel_uri - is the value a well-formed telephone uri?" .Vb 1 \& is_tel_uri($value); .Ve .RS 4 .IP "\fIDescription\fR" 4 .IX Item "Description" Specialized version of \fIis_uri()\fR that only likes tel: urls. As a result, it can also do a much more thorough job validating according to \s-1RFC 3966.\s0 .Sp Returns the untainted \s-1URI\s0 if the test value appears to be well-formed. .IP "\fIArguments\fR" 4 .IX Item "Arguments" .RS 4 .PD 0 .ie n .IP "$value" 4 .el .IP "\f(CW$value\fR" 4 .IX Item "$value" .PD The potential \s-1URI\s0 to test. .RE .RS 4 .RE .IP "\fIReturns\fR" 4 .IX Item "Returns" Returns the untainted \s-1URI\s0 on success, undef on failure. .IP "\fINotes, Exceptions, & Bugs\fR" 4 .IX Item "Notes, Exceptions, & Bugs" This function does not make any attempt to check whether the \s-1URI\s0 is accessible or 'makes sense' in any meaningful way. It just checks that it is formatted correctly. .RE .RS 4 .RE .SH "SEE ALSO" .IX Header "SEE ALSO" \&\s-1URI\s0, \s-1RFC 3986, RFC 3966, RFC 4694, RFC 4759, RFC 4904\s0 .SH "AUTHOR" .IX Header "AUTHOR" Richard Sonnen <\fIsonnen@richardsonnen.com\fR>. .PP is_tel_uri by David Dick <\fIddick@cpan.org\fR>. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2005 Richard Sonnen. All rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.