Browse Source

Escape double quotes in URL passed to browse-url

Escape double quotes in URL passed to browse-url

* lisp/org.el (org-link-escape-chars-browser): Add char double quote.
* lisp/org.el (org-open-at-point): Make use of the constant
`org-link-escape-chars-browser'.
* testing/lisp/test-org.el
(test-org/org-link-unescape-ascii-extended-char): Fill paragraph.
(test-org/org-link-escape-url-with-escaped-char): Fill paragraph and
typo.
(test-org/org-link-escape-chars-browser): New test.

This is to make work to open the Org link
[[http://some.host.com/search?q="Org mode"]] in a browser.

From 28726bcc7b7c440d70e2d95ea5a61d0cd5f084ea Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Sun, 5 May 2013 17:02:18 +0200
Subject: [PATCH] Escape double quotes in URL passed to browse-url

* lisp/org.el (org-link-escape-chars-browser): Add char double quote.
* lisp/org.el (org-open-at-point): Make use of the constant
`org-link-escape-chars-browser'.
* testing/lisp/test-org.el
(test-org/org-link-unescape-ascii-extended-char): Fill paragraph.
(test-org/org-link-escape-url-with-escaped-char): Fill paragraph and
typo.
(test-org/org-link-escape-chars-browser): New test.

This is to make work to open the Org link
[[http://some.host.com/search?q="Org mode"]] in a browser.
Michael Brand 4 years ago
parent
commit
9998f2c897
2 changed files with 30 additions and 12 deletions
  1. 17 9
      lisp/org.el
  2. 13 3
      testing/lisp/test-org.el

+ 17 - 9
lisp/org.el

@@ -9693,7 +9693,7 @@ according to FMT (default from `org-email-link-description-format')."
 This is the list that is used for internal purposes.")
 
 (defconst org-link-escape-chars-browser
-  '(?\ )
+  '(?\  ?\")
   "List of escapes for characters that are problematic in links.
 This is the list that is used before handing over to the browser.")
 
@@ -10423,16 +10423,24 @@ application the system uses for this file type."
 	      (apply cmd (nreverse args1))))
 
 	   ((member type '("http" "https" "ftp" "news"))
-	    (browse-url (concat type ":" (if (org-string-match-p "[[:nonascii:] ]" path)
-					     (org-link-escape
-					      path org-link-escape-chars-browser)
-					   path))))
+	    (browse-url
+	     (concat type ":"
+		     (if (org-string-match-p
+			  (concat "[[:nonascii:]"
+				  org-link-escape-chars-browser "]")
+			  path)
+			 (org-link-escape path org-link-escape-chars-browser)
+		       path))))
 
 	   ((string= type "doi")
-	    (browse-url (concat org-doi-server-url (if (org-string-match-p "[[:nonascii:] ]" path)
-						       (org-link-escape
-							path org-link-escape-chars-browser)
-						     path))))
+	    (browse-url
+	     (concat org-doi-server-url
+		     (if (org-string-match-p
+			  (concat "[[:nonascii:]"
+				  org-link-escape-chars-browser "]")
+			  path)
+			 (org-link-escape path org-link-escape-chars-browser)
+		       path))))
 
 	   ((member type '("message"))
 	    (browse-url (concat type ":" path)))

+ 13 - 3
testing/lisp/test-org.el

@@ -395,15 +395,25 @@
   (should
    (string=
     "àâçèéêîôùû"
-        (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
+        (decode-coding-string
+	 (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
 
 (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
-  "Escape and unscape a URL that includes an escaped char.
+  "Escape and unescape a URL that includes an escaped char.
 http://article.gmane.org/gmane.emacs.orgmode/21459/"
   (should
    (string=
     "http://some.host.com/form?&id=blah%2Bblah25"
-    (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
+    (org-link-unescape
+     (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
+
+(ert-deftest test-org/org-link-escape-chars-browser ()
+  "Escape a URL to pass to `browse-url'."
+  (should
+   (string=
+    "http://some.host.com/search?q=%22Org%20mode%22"
+    (org-link-escape "http://some.host.com/search?q=\"Org mode\""
+		     org-link-escape-chars-browser))))