URI::Normalize(3pm)
π URI::Normalize β bestie edition π
okay so this is a User Contributed Perl Documentation page for URI::Normalize(3pm), and honestly? it's a little bop. it's all about making URIs look β¨consistentβ¨ so you can actually compare them without losing your whole mind. let's get into it π«Ά
πΈ NAME πΈ
URI::Normalize β normalizes URIs according to RFC 3986. that's the vibe. periodt.
π VERSION π
version 0.002 π
β¨ SYNOPSIS β¨
here's the whole thing, no edits, no notes:
use URI;
use URI::Normalize qw( normalize_uri remove_dot_segments );
my $uri = URI->new('HTTPS://www.Example.com:443/../test/../foo/index.html');
say normalize_uri($uri); #> https://www.example.com/foo/index.html
say remove_dot_segments($uri); #> HTTPS://www.Example.com:443/foo/index.html
so like, normalize_uri goes all in and gives you the fully cleaned-up version, while remove_dot_segments is the more lowkey one that just deals with the .. and . drama in the path. notice the difference bestie, it's giving different jobs π
π¦ DESCRIPTION π¦
Section 6 of RFC 3986 lays out a whole process for URI normalization, and this module implements it. specifically, it does syntax-based normalization, and it may also include some schema-based and protocol-based normalization. it also implements the "remove_dot_segments" algorithm from Section 5.2.3 of the RFC. iconic behavior, no cap.
the practical glow-up here is that you can compare URIs with fewer false negatives. like, all of these bad boys:
HTTPS://www.example.com:443/../test/../foo/index.html
https://WWW.EXAMPLE.COM/./foo/index.html
https://www.example.com/%66%6f%6f/index.html
https://www.example.com/foo/index.html
will all normalize to the same value. and that value? the last one. yes literally all four of them. they all ate and left no crumbs, same crumbs actually π
π SUBROUTINES π
π normalize_uri
$normal_uri = normalize_uri($uri);
$normal_uri = normalize_uri($str);
hand it a URI object or a plain string, and this routine basically just calls the "canonical" method plus "remove_dot_segments" on the URI, then hands you back the result as a URI object. so easy, so slay.
the original URI is left unchanged. your input is safe bestie, we do not touch π«Ά
π remove_dot_segments
$clean_path_uri = remove_dot_segments($uri);
$clean_path_uri = remove_dot_segments($str);
give it a URI object or a string and it will remove dot segments β that's "." and ".." β from the path of the URI. that's it, that's the job π
π CAVEATS π
okay this is the serious part, bestie, listen up:
as RFC 3986 itself notes, normalization is a tool to help you figure out whether one URI is equivalent to another. but β and this is the big but β that does not mean that the resources identified by two URIs that are different byte-for-byte but normalize to the same value are actually the same resource. for example, the presence of "/./" in the path might be significant to some implementation, or using octet-encoding (like "%3a") instead of the character it represents might point at a different actual resource. so please, use normalization judiciously. don't be reckless with it π
also, this implementation of normalization is far from comprehensive. there are many normalizations you might wish you had. in that case, you may want to look into URL::Normalize, which provides a more comprehensive list of normalizations β some of which go against the letter of RFC 3986, but can be valuable in certain applications. ymmv, do your research π
this implementation does not include the full gamut of what's keeping with the letter of RFC 3986, but it might be expanded to include additional normalizations in the future. so like, watch this space β¨
and if you know of a normalization that could be implemented here: patches welcome. that's a direct quote, i'm not making it up, go contribute bestie π₯
π AUTHOR π
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> π
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2016 by Qubling Software.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. go off, legally speaking π
and that's the whole page, bestie!! it's URI::Normalize, version 0.002, from perl v5.30.3, dated 2020-09-22 β normalize responsibly, stan RFC 3986, and don't forget that normalization β same resource, okay?? mwah π
πβ¨
π¦ where this page comes from
- debian bookworm: liburi-normalize-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: liburi-normalize-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: liburi-normalize-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liburi-normalize-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liburi-normalize-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liburi-normalize-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms