emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Escape link path only if path contains space or non-ascii character
@ 2011-12-18 18:31 David Maus
  2011-12-20 22:54 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: David Maus @ 2011-12-18 18:31 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 553 bytes --]

Hi there,

Attached patch should take care of mistakenly double-escaped links as
reported by Jeff Horn in <http://article.gmane.org/gmane.emacs.orgmode/48731>.

This patch might break `org-open-at-point' for some users if the
target application does not deal with (possibly) unescaped URLs. The
alternative to the guesswork would require parsing und analyzing the
link and its components (path, query, fragment) and check for
characters that absolutely need escaping depeding on the link type.

Hopefully this solution is good enough.

Best,
  -- David

[-- Attachment #1.2: 0001-Escape-link-path-only-if-path-contains-space-or-non-.patch --]
[-- Type: text/plain, Size: 1708 bytes --]

From ddb461326896825dce6fd58bfd9e4ea25a3a35ff Mon Sep 17 00:00:00 2001
From: David Maus <dmaus@ictsoc.de>
Date: Sun, 18 Dec 2011 19:23:57 +0100
Subject: [PATCH] Escape link path only if path contains space or non-ascii character

* org.el (org-open-at-point): Escape link path for http:, https:,
ftp:, news:, and doi: links only if the path contains space or
non-ascii character.

This should take care of mistakenly double-escaped links as reported
by Jeff Horn in <http://article.gmane.org/gmane.emacs.orgmode/48731>.

We are just guessing here and push the responsibility for proper
escaping to the target application.
---
 lisp/org.el |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 8a1fbd3..1274f24 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9569,13 +9569,16 @@ application the system uses for this file type."
 	    (apply cmd (nreverse args1))))
 
 	 ((member type '("http" "https" "ftp" "news"))
-	  (browse-url (concat type ":" (org-link-escape
-					path org-link-escape-chars-browser))))
+	  (browse-url (concat type ":" (if (org-string-match-p "[[:nonascii:] ]" path)
+					   (org-link-escape
+					    path org-link-escape-chars-browser)
+					 path))))
 
 	 ((string= type "doi")
-	  (browse-url (concat "http://dx.doi.org/"
-                              (org-link-escape
-                               path org-link-escape-chars-browser))))
+	  (browse-url (concat "http://dx.doi.org/" (if (org-string-match-p "[[:nonascii:] ]" path)
+						       (org-link-escape
+							path org-link-escape-chars-browser)
+						     path))))
 
 	 ((member type '("message"))
 	  (browse-url (concat type ":" path)))
-- 
1.7.2.5


[-- Attachment #2: Type: application/pgp-signature, Size: 230 bytes --]

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

* Re: [PATCH] Escape link path only if path contains space or non-ascii character
  2011-12-18 18:31 [PATCH] Escape link path only if path contains space or non-ascii character David Maus
@ 2011-12-20 22:54 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2011-12-20 22:54 UTC (permalink / raw)
  To: David Maus; +Cc: emacs-orgmode

Hi David,

David Maus <dmaus@ictsoc.de> writes:

> Attached patch should take care of mistakenly double-escaped links as
> reported by Jeff Horn in <http://article.gmane.org/gmane.emacs.orgmode/48731>.
>
> This patch might break `org-open-at-point' for some users if the
> target application does not deal with (possibly) unescaped URLs. The
> alternative to the guesswork would require parsing und analyzing the
> link and its components (path, query, fragment) and check for
> characters that absolutely need escaping depeding on the link type.
>
> Hopefully this solution is good enough.

Guessing is probably safe here -- tests will tell.  Thanks for 
following this issue so closely and thanks for the patch!  I've
now applied it.

Best,

-- 
 Bastien

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

end of thread, other threads:[~2011-12-20 22:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-18 18:31 [PATCH] Escape link path only if path contains space or non-ascii character David Maus
2011-12-20 22:54 ` Bastien

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).