You are here: Foswiki>Tasks Web>Item13103 (12 Dec 2017, GeorgeClark)Edit Attach

Item13103: INCLUDE breaks relative links in attachments

pencil
Priority: Normal
Current State: Waiting for Feedback
Released In: n/a
Target Release: n/a
Applies To: Engine
Component: INCLUDE
Branches:
Reported By: AlexanderSulfrian
Waiting For: AlexanderSulfrian
Last Change By: GeorgeClark
If you include an attachment relative links get rewritten and get absolute URLs but does not contain the path to the attachment (missing the web and the topic).

The problem is that the replacement function (_cleanupIncludeHTML) only gets the $Foswiki::cfg{PubUrlPath} as path for the included document (and removes the last part, because it should be the included file name). The problem only occurs while including an attachment, and happoens because the code for handling remote URLs simply splits the host and the path at the first / after the protocol in the included URL. The attachment handler uses a regexp to parse the included URL and exactly split the web and the topic name that is needed for reading the attachment.

This patch should fix the problem:

diff --git a/lib/Foswiki/IncludeHandlers/http.pm b/lib/Foswiki/IncludeHandlers/http.pm
--- a/lib/Foswiki/IncludeHandlers/http.pm
+++ b/lib/Foswiki/IncludeHandlers/http.pm
@@ -58,7 +58,7 @@ sub INCLUDE {
             $fh->close();
             $text =
               _cleanupIncludedHTML( $text, $session->{urlHost},
-                $Foswiki::cfg{PubUrlPath}, $options )
+                "$Foswiki::cfg{PubUrlPath}/$incWeb/$incTopic/$incAtt", $options )
               unless $control->{raw};
             $text =
               Foswiki::applyPatternToIncludedText( $text, $control->{pattern} )

-- AlexanderSulfrian - 18 Nov 2014

needs a unit test for 1.2, a this code has just changed quite significantly.

-- CrawfordCurrie - 19 Nov 2014

Could you provide a more complete example of what you are including and what is not getting rewritten correctly? I don't understand the issue.

-- GeorgeClark - 26 Dec 2014

I rewrote the description to make it a bit clearer. This may be a genuine problem, it needs to be triaged.

-- Main.CrawfordCurrie - 20 Jun 2015 - 08:39

I really need a good example of how to recreate this.

-- GeorgeClark - 12 Dec 2017
 
Topic revision: r5 - 12 Dec 2017, GeorgeClark - This page was cached on 05 Jun 2020 - 17:40.

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