Commits

Diab Jerius committed 2e39242

clean up generation of attach URL

The old code sometimes added an extra /, creating an incorrect URL.
A side effect of the new approach is that path segments are properly
encoded.

Comments (0)

Files changed (1)

 
   my ( $config, $topic_path, $files ) = @_;
 
-  my $uri = $config->get( 'uri' );
-  my $bin_path = $config->get( 'bin_path' );
+  my $uri = $config->get( 'uri' )->clone;
 
+  $uri->path_segments
+    ( grep { $_ ne '' } $uri->path_segments,
+      split( '/', $config->get( 'bin_path' ) ),
+      'attach',
+      split( '/', $topic_path  )
+    );
 
-  # use URI package here?
-  my $bin_url = join( '/', $uri, $bin_path );
 
-  info "Base URL: $uri\n",
-       "bin path: $bin_path\n",
-       "Topic path: $topic_path\n"
-	  ;
-
-  msg "URL: $bin_path/upload/$topic_path\n";
-
+  info "Base URI: " . $config->get( 'uri' ) . "\n",
+       "Topic path: $topic_path\n",
+       "URI: $uri\n"
+	 ;
 
   my $ua = WikiUp::UserAgent->new( config => $config, quiet => 1 );
 
 	  next if $response =~ /n/i;
       }
 
-      my $url = "$bin_url/attach/$topic_path";
-
       # Foswiki requires a modified validation key to be uploaded with
       # the file (if the validation method is strikeone).  It seems
       # the only means of getting the original key is from a Foswiki
       # of keeping the code simple, I've decided to use the
       # screen-scraping method for both.
 
-      $ua->get( $url );
-      die( "error accessing Topic ($topic_path) via $url: ",
+      $ua->get( $uri );
+      die( "error accessing Topic ($topic_path) via $uri: ",
 	   $ua->response->message, "\n")
 	unless $ua->success;