Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Path-Class-URI CPAN distribution.

Report information
The Basics
Id: 87929
Status: resolved
Priority: 0/
Queue: Path-Class-URI

People
Owner: zmughal [...] cpan.org
Requestors: zmughal [...] cpan.org
Cc: zmughal [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



CC: zmughal [...] cpan.org
Subject: URI escaping
Hello, I have attached a patch from <https://github.com/zmughal/Path-Class-URI/commit/01a03255472ddd38ac8dcb50b4bc017aa84871ff> that handles the case when paths contain characters that need to be escaped for the URI. Cheers, - zaki
Subject: components-of-path-must-be-escaped-for-URI.patch
From 01a03255472ddd38ac8dcb50b4bc017aa84871ff Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal <zaki.mughal@gmail.com> Date: Sun, 18 Aug 2013 23:01:27 -0500 Subject: [PATCH] components of path must be escaped for URI --- lib/Path/Class/URI.pm | 5 ++++- t/04_escaping.t | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 t/04_escaping.t diff --git a/lib/Path/Class/URI.pm b/lib/Path/Class/URI.pm index c40f6be..0a32e30 100644 --- a/lib/Path/Class/URI.pm +++ b/lib/Path/Class/URI.pm @@ -9,6 +9,7 @@ use URI::file; use Exporter::Lite; use Path::Class; use Scalar::Util qw(blessed); +use URI::Escape; our @EXPORT = qw( file_from_uri dir_from_uri ); @@ -22,7 +23,9 @@ sub dir_from_uri { sub Path::Class::Entity::uri { my $self = shift; - my $path = $self->stringify; + my $escaped_self = $self->new( map { uri_escape($_) } $self->components ); + # escape the components so that URI can see them as path segments + my $path = $escaped_self->stringify; $path =~ tr!\\!/! if $^O eq "MSWin32"; $path .= '/' if $self->isa('Path::Class::Dir'); # preserve directory if used as base URI if ($self->is_absolute) { diff --git a/t/04_escaping.t b/t/04_escaping.t new file mode 100644 index 0000000..770c67e --- /dev/null +++ b/t/04_escaping.t @@ -0,0 +1,38 @@ +use strict; +use Test::Base; + +use Path::Class; +use Path::Class::URI; +plan tests => 4 * blocks; + +filters 'chomp'; + +run { + my $block = shift; + + { + my $file = file($block->input); + my $file_back = file_from_uri($file->uri); + isa_ok $file_back, 'Path::Class::File'; + is $file_back, $file; + } + + { + my $dir = dir($block->input); + my $dir_back = dir_from_uri($dir->uri); + isa_ok $dir_back, 'Path::Class::Dir'; + is $dir_back, $dir; + } +}; + +__END__ + +=== +--- input +/path/to/test/download;jsessionid=ABC.pdf +=== +--- input +/a/b;c/d;e +=== +--- input +/a/b%c/d%e -- 1.7.10.4