preserve fragments and stick them on the end of URLs
Mischa S [Mon, 27 Jul 2015 07:53:03 +0000 (00:53 -0700)]
lib/Catalyst.pm
t/aggregate/unit_core_uri_for.t

index 891b722..9398f71 100644 (file)
@@ -1632,6 +1632,12 @@ sub uri_for {
 
     my $query = '';
 
+    # remove and save fragment if there is one
+    my $fragment;
+    if ($args =~ s/(#.+)$//) {
+      $fragment = $1;
+    }
+
     if (my @keys = keys %$params) {
       # somewhat lifted from URI::_query's query_form
       $query = '?'.join('&', map {
@@ -1660,7 +1666,10 @@ sub uri_for {
     $base =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
     $args = encode_utf8 $args;
     $args =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
-    
+
+    # re-attach fragment on the end of everything after adding params
+    $query .= $fragment if $fragment;
+
     my $res = bless(\"${base}${args}${query}", $class);
     $res;
 }
index 3318192..d3696a2 100644 (file)
@@ -59,14 +59,11 @@ is(
     'Plus is not encoded'
 );
 
-TODO: {
-    local $TODO = 'broken by 5.7008';
-    is(
-        Catalyst::uri_for( $context, '/bar#fragment', { param1 => 'value1' } )->as_string,
-        'http://127.0.0.1/foo/bar?param1=value1#fragment',
-        'URI for path with fragment and query params'
-    );
-}
+is(
+    Catalyst::uri_for( $context, '/bar#fragment', { param1 => 'value1' } )->as_string,
+    'http://127.0.0.1/foo/bar?param1=value1#fragment',
+    'URI for path with fragment and query params'
+);
 
 # test with utf-8
 is(