• Do not register here on develop.twiki.org, login with your twiki.org account.
• Use View topic Item7848 for generic doc work for TWiki-6.1.1. Use View topic Item7851 for doc work on extensions that are not part of a release. More... Close
• Anything you create or change in standard webs (Main, TWiki, Sandbox etc) will be automatically reverted on every SVN update.
Does this site look broken?. Use the LitterTray web for test cases.

Item7132: Redirect query-string pass-through breaks on URLs containing fragments

Item Form Data

AppliesTo: Component: Priority: CurrentState: WaitingFor: TargetRelease ReleasedIn
Engine   Normal New   n/a  

Edit Form Data

Reported By:
Applies To:
Current State:
Waiting For:
Target Release:
Released In:


The "pass through" mechanism for transferring query parameters through a redirect (implemented in the method redirect of TWiki.pm) does not seem to work when the redirect target URL contains a fragment (i.e. ends in an #anchor). Since the code isn't aware of URL fragments, it creates a target URL that looks like http://server/path#fragment?query=string, which is incorrect (fragments have to come after query strings) and thus doesn't result in the query string being passed through as desired. I noticed this because it breaks the feedback-notification function of TWiki:Plugins.SendEmailPlugin, see TWiki:Support.SendEmailPluginNoFeedback.

Attached ( redirect-fix.patch) is an easy fix that works for me, by not manipulating the URL manually but instead using URI.pm which understands all the parts of a URL.

-- TWiki:Main/MichaelShulman - 2013-01-29

Thank you Michael for the proposed patch!

I have not tried, but I just glanced over the patch. There might be an issue, not sure. You create a URL object based on the whole URL, including parameters. In case of the POST method, all URL parameters need to be removed, and only the twiki_redirect_cache=somestring should be added. May be I miss something, but it looks like you add twiki_redirect_cache=twiki_redirect_cache=somestring and keep the existing parameters.

May be a simple fix is to detect URL parameter delimiter (?) and anchor (#) ? That is:

if ($url =~ s/[\?#](.*)$//) {

Please advise.

-- TWiki:Main.PeterThoeny - 2013-01-29

Firstly, somehow my attachment omitted part of the patch: I also modified the last line of cacheQuery to be just return $uid;. Hence what gets added to the query is actually just twiki_redirect_cache=somestring. Sorry about that!

Second, it looks to me like what the existing code does in the case of a POST method is assume that there are no existing URL parameters by adding ?twiki_redirect_cache=somestring at the end of the URL. What my patch does instead is to add twiki_redirect_cache=somestring to any existing URL parameters, which seems like better behavior to me. If we want to remove the existing URL parameters in the POST case, it would be easy to do with $urlobj->query_form('') before the call to query_param_append.

In general, it seems to me to be a better idea to use a package designed specifically to manipulate URLs rather than writing regexes by hand.

-- TWiki:Main.MichaelShulman - 2013-02-05

Summary Redirect query-string pass-through breaks on URLs containing fragments
ReportedBy TWiki:Main.MichaelShulman
Codebase 5.1.3
SVN Range TWiki-5.1.3-trunk, Fri, 11 Jan 2013, build 24780
AppliesTo Engine

Priority Normal
CurrentState New


TargetRelease n/a

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatpatch redirect-fix.patch r1 manage 1.4 K 2013-01-29 - 17:01 MichaelShulman  
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View |  Raw edit | More topic actions
Topic revision: r3 - 2013-02-05 - MichaelShulman
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback