emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: org-make-link-string incorrect with URL containing escapes [6.34a]
@ 2010-01-15 13:41 Geert Kloosterman
  2010-01-16  0:11 ` Carsten Dominik
  0 siblings, 1 reply; 2+ messages in thread
From: Geert Kloosterman @ 2010-01-15 13:41 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2374 bytes --]

Emacs  : GNU Emacs 23.1.1 (i386-redhat-linux-gnu, GTK+ Version 2.18.3)
 of 2009-12-02 on x86-7.fedora.phx.redhat.com
Package: Org-mode version 6.34a

Hi all,

When an org link is created from an URL containing a hex escape
`org-make-link-string' creates a link that ends up corrupted the moment
it is followed (e.g. using `org-open-at-point').

I've traced this back to `org-link-escape' and `org-link-unescape'.  The
following shows how the hex code "%2B" is converted to a "+" after an
escaping round trip:

    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah"))
    ==> 
    "http://some.host.com/form?&id=blah+blah"

In my case this small change ended up in a broken URL.

Additionally, when the URL-escape happens to be in lower case (or
otherwise not present in `org-link-escape-chars') we end up with an
error:

    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2bblah"))
    ==> 
    Debugger entered--Lisp error: (wrong-type-argument characterp nil)
      char-to-string(nil)
      ...

When `org-url-encoding-use-url-hexify' is set to `t' we do get a proper
round trip of the URL containing hex-escapes:

    (setq org-url-encoding-use-url-hexify t)
    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2bblah"))
    ==>
    "http://some.host.com/form?&id=blah%2bblah"


Setting `org-url-encoding-use-url-hexify' does not fix the complete
problem however: `org-open-at-point' still did not end up with the
proper URL.   Within `org-open-at-point' there is another call to
`org-link-escape':

    (org-link-escape path org-link-escape-chars-browser)

This time a mapping table is passed in explicitly (the second argument).
However, when `org-url-encoding-use-url-hexify' is set,a this mapping
table isn't used, resulting (again) in a broken URL.

I have attached a patch that fixes the problem: do not use url-hexify in
`org-link-escape' and `org-link-unescape' when an explicit mapping table
has been specified.  

In summary:
 - the default behaviour of `org-link-escape', with
   `org-url-encoding-use-url-hexify' set to nil, has some issues with
   handling URLS which contain url-encoded hex escapes
 - when a mapping table is passed to `org-link-escape' and
   `org-link-unescape', they should probably not use url-hexify.
   Patch attached. 

Best regards,
Geert Kloosterman



[-- Attachment #2: org.el.diff --]
[-- Type: text/x-patch, Size: 741 bytes --]

--- org.el.orig	2010-01-12 08:54:31.000000000 +0100
+++ org.el	2010-01-15 14:14:38.000000000 +0100
@@ -7893,7 +7893,7 @@
 
 (defun org-link-escape (text &optional table)
   "Escape characters in TEXT that are problematic for links."
-  (if org-url-encoding-use-url-hexify
+  (if (and org-url-encoding-use-url-hexify (not table))
       (url-hexify-string text)
     (setq table (or table org-link-escape-chars))
     (when text
@@ -7910,7 +7910,7 @@
 
 (defun org-link-unescape (text &optional table)
   "Reverse the action of `org-link-escape'."
-  (if org-url-encoding-use-url-hexify
+  (if (and org-url-encoding-use-url-hexify (not table))
       (url-unhex-string text)
     (setq table (or table org-link-escape-chars))
     (when text

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Bug: org-make-link-string incorrect with URL containing escapes [6.34a]
  2010-01-15 13:41 Bug: org-make-link-string incorrect with URL containing escapes [6.34a] Geert Kloosterman
@ 2010-01-16  0:11 ` Carsten Dominik
  0 siblings, 0 replies; 2+ messages in thread
From: Carsten Dominik @ 2010-01-16  0:11 UTC (permalink / raw)
  To: Geert Kloosterman; +Cc: emacs-orgmode

Hi Geert,

wow, this was awesome!  This is the best kind of bug report I can  
imagine.
Thank you, your patch has been applied.

- Carsten

On Jan 15, 2010, at 2:41 PM, Geert Kloosterman wrote:

> Emacs  : GNU Emacs 23.1.1 (i386-redhat-linux-gnu, GTK+ Version 2.18.3)
> of 2009-12-02 on x86-7.fedora.phx.redhat.com
> Package: Org-mode version 6.34a
>
> Hi all,
>
> When an org link is created from an URL containing a hex escape
> `org-make-link-string' creates a link that ends up corrupted the  
> moment
> it is followed (e.g. using `org-open-at-point').
>
> I've traced this back to `org-link-escape' and `org-link-unescape'.   
> The
> following shows how the hex code "%2B" is converted to a "+" after an
> escaping round trip:
>
>    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah 
> "))
>    ==>
>    "http://some.host.com/form?&id=blah+blah"
>
> In my case this small change ended up in a broken URL.
>
> Additionally, when the URL-escape happens to be in lower case (or
> otherwise not present in `org-link-escape-chars') we end up with an
> error:
>
>    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2bblah 
> "))
>    ==>
>    Debugger entered--Lisp error: (wrong-type-argument characterp nil)
>      char-to-string(nil)
>      ...
>
> When `org-url-encoding-use-url-hexify' is set to `t' we do get a  
> proper
> round trip of the URL containing hex-escapes:
>
>    (setq org-url-encoding-use-url-hexify t)
>    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2bblah 
> "))
>    ==>
>    "http://some.host.com/form?&id=blah%2bblah"
>
>
> Setting `org-url-encoding-use-url-hexify' does not fix the complete
> problem however: `org-open-at-point' still did not end up with the
> proper URL.   Within `org-open-at-point' there is another call to
> `org-link-escape':
>
>    (org-link-escape path org-link-escape-chars-browser)
>
> This time a mapping table is passed in explicitly (the second  
> argument).
> However, when `org-url-encoding-use-url-hexify' is set,a this mapping
> table isn't used, resulting (again) in a broken URL.
>
> I have attached a patch that fixes the problem: do not use url- 
> hexify in
> `org-link-escape' and `org-link-unescape' when an explicit mapping  
> table
> has been specified.
>
> In summary:
> - the default behaviour of `org-link-escape', with
>   `org-url-encoding-use-url-hexify' set to nil, has some issues with
>   handling URLS which contain url-encoded hex escapes
> - when a mapping table is passed to `org-link-escape' and
>   `org-link-unescape', they should probably not use url-hexify.
>   Patch attached.
>
> Best regards,
> Geert Kloosterman
>
>
> <org.el.diff>_______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

- Carsten

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-16  0:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-15 13:41 Bug: org-make-link-string incorrect with URL containing escapes [6.34a] Geert Kloosterman
2010-01-16  0:11 ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).