Tags:
create new tag
view all tags

SID-01186: Interwiki does not encode URLs?

Status: Answered Answered TWiki version: 4.2.3 Perl version: 5.8.8
Category: InterwikiPlugin Server OS: Fedora Last update: 14 years ago

I decided to try to use InterwikiPlugin to simplify referencing photos in an external website.

The rules don't seem flexible enough - or I haven't figured out how to accomplish what's needed.

Here's what an external URL looks like:

https://www.example.com/photos/gallery.cgi?mode=view&photo=%2FFamily%2FDog%20Jumping%2F100_1027.jpg

One would like these to work like:

Photo:'/Family/Dog Jumping/100_1027.jpg', where the quotes are necessary because of the embedded space.

Or, even

[[Photo:/Family/Dog Jumping/100_1027.jpg]]

So I tried:

| Photo | https://www.example.com/photos/gallery.cgi?mode=view&photo=%ENCODE{$page}% | Display a photo '$page' from the internal photo gallery |

But: the %ENCODE was taken literally. I tried omitting the %ENCODE, but that doesn't quite work...

It looks to me like the syntax doesn't quite handle this external site.

I think we need a way to quote the string after Site:, and I think we need a way to specify that $page is to be url-encoded...

Or perhaps I'm missing something.

-- TimotheLitt - 2011-05-23

Discussion and Answer

Self-help: I have generated the attached patch Patch for quote syntax and urlencode which solves my problem.

The patch is based on the latest (2010-07-12) release; I changed the release to -T1, but you'll want to make it whatever date you re-package.

  • You can now specify an external link as Site:'anything at all' or Site:"anything at all", as well as Site:PreviousRestrictedSyntax. If you use either quote form, there is no escape character for the quotation mark that you choose; so if you need a single quote, use the double quote form and vice-versa. If you need both, you can make the regexes even more complex.
  • When the $page variable is interpolated into the URL (explicitly or implicitly appended), it is urlencoded. This allows spaces and other strange characters to be passed in the href.
  • If you use the $page variable elsewhere (e.g. for label or tooltip), it is NOT urlencoded, so the human readable stuff stays human readable.

I have not tested this with all the pre-defined interwikis (I don't have test URLs for them), but it should work. Hopefully there's a regression test for this plugin.

Let me know if there are any issues; if not, please put the patch into your source.

-- TimotheLitt - 2011-05-23

Thanks Timothe for the patch. I think it is too risky to change the behavior of URL encoding the $page part. I have used manually URL-encoded page names, so they would be double encoded, thus breaking the link.

I like however the idea of enclosing the page name in single quotes or double quotes. This is a new case where we can safely use the implicit URL encoding. This spec is an extension that does not break existing content.

-- PeterThoeny - 2011-05-24

That's too bad - the page should have been urlencoded from the start, but I do understand the legacy problem. Amazing what people will do with broken tools; manual urlencoding is truly ugly and hardly user friendly. But the compatibility argument is persuasive.

I have updated the patch to only urlencode when the page is quoted. That suffices for my needs and addresses your concern.

This is version T2.

Enjoy.

-- TimotheLitt - 2011-05-24

Thanks, tracked in TWikibug:Item6731.

-- PeterThoeny - 2011-05-26

This is now in SVN trunk and 5.1 branch. Plugins.InterwikiPlugin is updated as well.

FYI, it took some time to update the docs. I also did some code cleanup, adding $SHORTDESCRIPTION and $NO_PREFS_IN_TOPIC, and changing use vars qw() to our.

You have SVN access, you could help the TWiki community by checking in code and docs directly. Or if you prefer to just provide patches, it would help to get updated docs with it as well.

-- PeterThoeny - 2011-05-26

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title Interwiki does not encode URLs?
SupportCategory InterwikiPlugin
TWiki version 4.2.3
Server OS Fedora
Web server Apache
Perl version 5.8.8
Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatpatch interwiki_quote_encode.patch r3 r2 r1 manage 2.1 K 2011-05-24 - 09:48 UnknownUser Patch version T2 for quote syntax and urlencode if quoted
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2011-05-26 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.