http://www.perlmonks.org?node_id=437085


in reply to Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
in thread Monk Links - Copy Perlmonks-links to the clipboard in on-site-format

Ah, it seems I am not very good at writing documentations.
What would be cool for extentions, holli, is if you did likewise for perldoc, doc, and cpan links.
Actually I have a new version ready that works for cpan://* and kobes://* links, but there is a ugly bug. The entity %3A (double colon) gets not correctly decoded by the decodeURI function. I am trying to figure out why.

As for the perldoc, I will add that when I am sure the currently selected perldoc site will not change.


holli, /regexed monk/
  • Comment on Re^2: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
  • Download Code

Replies are listed 'Best First'.
Re^3: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by The Mad Hatter (Priest) on Mar 06, 2005 at 21:05 UTC
    As a quick hack, you could do decodeURI(s).replace('%3a',':');.
      Thanks a lot The Mad Hatter. But that must be decodeURI(s).replace(/%3a/gi,':');. Otherwise only the first occurance is replaced.


      holli, /regexed monk/
        Urk, you're right. Sorry about that.
Re^3: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by ikegami (Patriarch) on Nov 01, 2006 at 18:28 UTC

    decodeURI "does not decode escape sequences that could not have been introduced by encodeURI."

    In other words, decodeURI won't return an invalid URI, like decoding %3A does or could do. You can't safely decode an entire URI. Each path segment, each attribute key and each attribute value must be isolated before they can be decoded. For example http%3A//www.google.com/ (a relative URI) and http://www.google.com/ (an absolute URI) are not equivalent.

    Not what you want:

    decodeURI("http://search.cpan.org/search?mode=module&query=XML%3A%3APa +rser")

    What you want:

    decodeURIComponent("XML%3A%3AParser")

    Since your code already extracts the compenent, simply use

    clickedLink = "[cpan://" + decodeURIComponent(array[1]) + "]";
Re^3: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by belg4mit (Prior) on Nov 20, 2005 at 18:24 UTC
    That might be because decodeURI is a complement to encodeURI which encodes non-valid entities. : is avalid entity in a URI

    --
    In Bob We Trust, All Others Bring Data.