You are here: Foswiki>Tasks Web>Item13874 (03 Feb 2016, GeorgeClark)Edit Attach

Item13874: Don't encode URLs in links inserted by Upload

pencil
Priority: Enhancement
Current State: Closed
Released In: 2.1.0
Target Release: minor
Applies To: Engine
Component: FoswikiAttach, FoswikiUIAttach, I18N
Branches: Item13405 master
Reported By: GeorgeClark
Waiting For:
Last Change By: GeorgeClark
Current Upload / Attach of a uft-8 filename functions differently in the Wysiwyg link insert compared to Attach / Upload link insert.
  • WysiwygPlugin inserts the link using UNICODE characters, encoding is not performed
[[%PUBURL%/Litterbox/Úňíčôďě/ÁťťáčhméňťŤôpíč/FľléxPápěŕPĺúgíň.pdf][FľléxPápěŕPĺúgíň.pdf]]
  • Upload inserts the link and encodes non-ascii into entities.
[[%ATTACHURL%/F%c4%bel%c3%a9xP%c3%a1p%c4%9b%c5%95P%c4%ba%c3%bag%c3%ad%c5%88.pdf][FľléxPápěŕPĺúgíň.pdf]]
  • And after an Edit/Save cycle under Wysiwyg, the ATTACHURL link is converted to an PUBURL.
[[%PUBURL%/Litterbox/Úňíčôďě/ÁťťáčhméňťŤôpíč/F%c4%bel%c3%a9xP%c3%a1p%c4%9b%c5%95P%c4%ba%c3%bag%c3%ad%c5%88.pdf][FľléxPápěŕPĺúgíň.pdf]]
Both of these links will work fine. The Wysiwyg version is much more usable / editable by mere mortals. The link inserted by Manage Attachments is completely un-editable

Upload should be consistent with Wysiwyg.

-- GeorgeClark - 28 Nov 2015

Following patch seems to resolve the issue.

diff --git a/core/lib/Foswiki/Attach.pm b/core/lib/Foswiki/Attach.pm
index b7f74db..c25663f 100644
--- a/core/lib/Foswiki/Attach.pm
+++ b/core/lib/Foswiki/Attach.pm
@@ -373,9 +373,6 @@ sub getAttachmentLink {
     my $imgSize  = '';
     my $prefs    = $this->{session}->{prefs};
 
-    # I18N: URL-encode the attachment filename
-    my $fileURL = Foswiki::urlEncode($attName);
-
     if ( $attName =~ m/\.(gif|jpg|jpeg|png)$/i ) {
 
         # inline image
@@ -399,7 +396,7 @@ sub getAttachmentLink {
 
         $fileLink = $prefs->getPreference('ATTACHEDIMAGEFORMAT');
         unless ($fileLink) {
-            $attrs{src} = "%ATTACHURLPATH%/$fileURL";
+            $attrs{src} = "%ATTACHURLPATH%/$attName";
             $attrs{alt} = $attName;
             return "   * $fileComment: " . CGI::br() . CGI::img( \%attrs );
         }
@@ -409,16 +406,16 @@ sub getAttachmentLink {
         # normal attached file
         $fileLink = $prefs->getPreference('ATTACHEDFILELINKFORMAT');
         unless ($fileLink) {
-            return "   * [[%ATTACHURL%/$fileURL][$attName]]: $fileComment";
+            return "   * [[%ATTACHURL%/$attName][$attName]]: $fileComment";
         }
     }
 
     # I18N: Site specified %ATTACHEDIMAGEFORMAT% or %ATTACHEDFILELINKFORMAT%,
     # ensure that filename is URL encoded - first $name must be URL.
-    $fileLink =~ s/\$name/$fileURL/;        # deprecated
+    $fileLink =~ s/\$name/$attName/;        # deprecated
     $fileLink =~ s/\$name/$attName/;        # deprecated, see Item1814
     $fileLink =~ s/\$filename/$attName/g;
-    $fileLink =~ s/\$fileurl/$fileURL/g;
+    $fileLink =~ s/\$fileurl/$attName/g;
     $fileLink =~ s/\$fileext/$fileExt/;
 
     # Expand \t and \n early (only in the format, not
 
Topic revision: r6 - 03 Feb 2016, GeorgeClark - This page was cached on 18 Nov 2017 - 17:32.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License