emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Brand <michael.ch.brand@gmail.com>
To: Nicolas Goaziou <n.goaziou@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: Encoding Problem in export?
Date: Sat, 16 Nov 2013 16:16:04 +0100	[thread overview]
Message-ID: <CALn3zohotvk1Z52mD_QhKZOosc+ZRe1P1FX2AsmRVAVhe7XtqQ@mail.gmail.com> (raw)
In-Reply-To: <87txjk5s2q.fsf@gmail.com>

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

Hi Nicolas

I would like to ask you to review the attached patch so I can change
it when necessary before I git push it.

> it probably means that `org-link-escape' is a bit too zealous (BTW
> why don't this function rely on `url-encode-url'?)

url-encode-url is a very good hint to solve a different issue that
I try to deal with:

(from http://lists.gnu.org/archive/html/emacs-orgmode/2013-10/msg00204.html)
On Sat, Oct 5, 2013 at 3:04 PM, Michael Brand
<michael.ch.brand@gmail.com> wrote:
> [...] related change that I will suggest with an ERT in a later
> patch: Just add "+" to org-link-escape-chars-browser.

"+" has not been added to org-link-escape-chars-browser yet and in the
meantime I realized that it should not be added in order to not break
existing Org links like:

    [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query="Release+8.2"]]

that work the same as

    [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query="Release
8.2"]]

Better is to change the function org-link-escape-browser to use
url-encode-url when available (since Emacs 24.3). With this I can
write my use case to open a browser with +subject:"Release 8.2" in the
query field now as an Org link written manually with %2B for the "+"
at the beginning and %25 for its "%" like this

    [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:"Release+8.2"]]

or

    [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:"Release
8.2"]]

Link escaping in org-store-link and link unescaping in the first part
of org-open-at-point are not changed, this is important to keep
backward compatibility with old Org links. I have used this patch for
several weeks on Emacs 24.3.2 without any problem.

Michael

[-- Attachment #2: review.patch.txt --]
[-- Type: text/plain, Size: 4891 bytes --]

commit 686bd788243ef38951c3c529d4c67c3ad766f417
Author: Michael Brand <michael.ch.brand@gmail.com>
Date:   Sat Nov 16 16:13:57 2013 +0100

    Hyperlink: Use url-encode-url for browse-url
    
    * lisp/org.el (org-open-at-point): When available (Emacs 24.3) use
    `url-encode-url' instead of `org-link-escape-browser'.
    
    * testing/lisp/test-org.el
    (test-org/org-link-escape-url-with-escaped-char): Substitute repeated
    literal string with constant.
    (test-org/org-link-escape-chars-browser): Extend test coverage with
    `url-encode-url' and with "query="-space as plus sign or space.

diff --git a/lisp/org.el b/lisp/org.el
index a3c1958..aa91ffc 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10468,11 +10468,20 @@ 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-browser path))))
+	    ;; see `ert-deftest'
+	    ;; `test-org/org-link-escape-chars-browser'
+	    (browse-url
+	     (if (fboundp 'url-encode-url)
+		 (url-encode-url (concat type ":" path))
+	       (org-link-escape-browser (concat type ":" path)))))
 
 	   ((string= type "doi")
-	    (browse-url (concat org-doi-server-url
-				(org-link-escape-browser path))))
+	    ;; see `ert-deftest'
+	    ;; `test-org/org-link-escape-chars-browser'
+	    (browse-url
+	     (if (fboundp 'url-encode-url)
+		 (url-encode-url (concat org-doi-server-url path))
+	       (org-link-escape-browser (concat org-doi-server-url path)))))
 
 	   ((member type '("message"))
 	    (browse-url (concat type ":" path)))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index f4672eb..084e95d 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -552,21 +552,53 @@
 (ert-deftest test-org/org-link-escape-url-with-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")))))
+  (let ((a "http://some.host.com/form?&id=blah%2Bblah25"))
+    (should (string= a (org-link-unescape (org-link-escape a))))))
 
 (ert-deftest test-org/org-link-escape-chars-browser ()
-  "Escape a URL to pass to `browse-url'."
-  (should
-   (string=
-    (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
-	    "%22Release%208.2%22&idxname=emacs-orgmode")
-    (org-link-escape-browser
-     (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
-	     "\"Release 8.2\"&idxname=emacs-orgmode")))))
+  "Escape a URL before passing it to `browse-url'.
+
+This test is to ensure that `org-open-at-point' on the Org links
+
+    [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:\"Release+8.2\"]]
+    [[http://lists.gnu.org/archive/cgi-bin/namazu.cgi?idxname=emacs-orgmode&query=%252Bsubject:\"Release 8.2\"]]
+
+will open a browser with +subject:\"Release 8.2\" in the query
+field."
+
+  ;; Each string argument passed to `url-encode-url' or
+  ;; `org-link-escape-browser' in the tests below (or when
+  ;; `org-open-at-point' is used in an Org buffer) looks like after
+  ;; the Org link from the docstring has been unescaped by
+  ;; `org-link-unescape' in `org-open-at-point'
+  (let ((query (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?"
+		       "idxname=emacs-orgmode&query="))
+	(plus  "%2Bsubject:\"Release+8.2\"")   ; "query="-space as plus sign
+	(space "%2Bsubject:\"Release 8.2\""))  ; "query="-space as space
+
+    ;; This is the behavior of `org-open-at-point' when used together
+    ;; with an Emacs 24.3 or later where `url-encode-url' is available
+    (when (fboundp 'url-encode-url)
+      ;; "query="-space as plus sign
+      (should (string= (concat query "%2Bsubject:%22Release+8.2%22")
+		       (url-encode-url (concat query plus))))
+      ;; "query="-space as space
+      (should (string= (concat query "%2Bsubject:%22Release%208.2%22")
+		       (url-encode-url (concat query space)))))
+
+    ;; The %252B below returned from `org-link-escape-browser' is not
+    ;; desired and not working with some browser/OS but tested here to
+    ;; document what happens when the fallback to
+    ;; `org-link-escape-browser' in `org-open-at-point' is in use,
+    ;; which is the legacy behavior of `org-open-at-point' when used
+    ;; together with an Emacs before version 24.3
+    ;;
+    ;; "query="-space as plus sign
+    (should (string= (concat query "%252Bsubject:%22Release+8.2%22")
+		     (org-link-escape-browser (concat query plus))))
+    ;; "query="-space as space
+    (should (string= (concat query "%252Bsubject:%22Release%208.2%22")
+		     (org-link-escape-browser (concat query space))))))
 
 
 \f

  parent reply	other threads:[~2013-11-16 15:16 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-23 23:17 Encoding Problem in export? Robert Eckl
2013-07-23 23:35 ` Nicolas Goaziou
2013-07-24  1:50   ` Robert Eckl
2013-07-24  7:34     ` Nicolas Goaziou
2013-07-24  8:46       ` Robert Eckl
2013-07-24  9:16         ` Nicolas Goaziou
2013-07-24 10:27           ` Robert Eckl
2013-07-24  9:39       ` Nick Dokos
2013-07-24 11:09         ` Nicolas Goaziou
2013-07-25  4:05           ` David Maus
2013-07-25 21:46             ` Nicolas Goaziou
2013-07-26  4:03               ` David Maus
2013-07-26 10:20                 ` Nicolas Goaziou
2013-07-27  7:23                   ` David Maus
2013-07-27 11:09                     ` Nicolas Goaziou
2013-07-28  8:36                       ` Jambunathan K
2013-07-28  8:54                         ` Jambunathan K
2013-07-28 11:16                         ` David Maus
2013-07-28 11:22                         ` Nicolas Goaziou
2013-07-29  6:59                           ` Jambunathan K
2013-11-16 15:16       ` Michael Brand [this message]
2013-11-16 20:43         ` Nicolas Goaziou
2013-11-17 11:06           ` Michael Brand
2013-11-17 11:46             ` Nicolas Goaziou
2013-11-17 11:51               ` Michael Brand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALn3zohotvk1Z52mD_QhKZOosc+ZRe1P1FX2AsmRVAVhe7XtqQ@mail.gmail.com \
    --to=michael.ch.brand@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=n.goaziou@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).