Org-mode mailing list
 help / color / mirror / Atom feed
From: Maxim Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH 3/3] test-org-protocol.el: Add expected failures for file:/// URLs
Date: Sun, 4 Apr 2021 21:44:58 +0700
Message-ID: <s4cjdb$156g$3@ciao.gmane.io> (raw)
In-Reply-To: <s4cim4$47c$1@ciao.gmane.io>

* testing/lisp/test-org-protocol.el
(test-org-protocol/org-protocol-store-link-file,
test-org-protocol/org-protocol-capture-file): Add tests to document
that existing calls to `org-protocol-sanitize-uri' could make passed
URLs invalid by changing number of slashes after scheme.

Till a fix of the problem the new tests are marked as expected failures.

Unless a relatively recent commit 5748615c48, I would believe that
`org-protocol-sanitize-uri' was added by mistake to the initial
implementation.  Capture URLs are anyway escaped with percent encoding.
---
 testing/lisp/test-org-protocol.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/testing/lisp/test-org-protocol.el b/testing/lisp/test-org-protocol.el
index 5ab96fdc2..d33052b30 100644
--- a/testing/lisp/test-org-protocol.el
+++ b/testing/lisp/test-org-protocol.el
@@ -78,6 +78,16 @@
     (should (null (org-protocol-check-filename-for-protocol uri (list uri) nil)))
     (should (equal (car org-stored-links) '("URL3" "TITLE3")))))
 
+(ert-deftest test-org-protocol/org-protocol-store-link-file ()
+  "store-link: `org-protocol-sanitize-uri' could distort URL."
+  :expected-result :failed
+  (let ((uri "/org-protocol:/store-link:/file%3A%2F%2F%2Fetc%2Fmailcap/Triple%20Slash"))
+    (should (null (org-protocol-check-filename-for-protocol uri (list uri) nil)))
+    (should (equal (car org-stored-links) '("file:///etc/mailcap" "Triple Slash"))))
+  (let ((uri "/org-protocol:/store-link?url=file%3A%2F%2F%2Fetc%2Fmailcap&title=Triple%20Slash"))
+    (should (null (org-protocol-check-filename-for-protocol uri (list uri) nil)))
+    (should (equal (car org-stored-links) '("file:///etc/mailcap" "Triple Slash")))))
+
 (ert-deftest test-org-protocol/org-protocol-capture ()
   "Test `org-protocol-capture' specifications."
   (let* ((org-protocol-default-template-key "t")
@@ -134,6 +144,20 @@
      test-urls)
     (delete-file temp-file-name)))
 
+(ert-deftest test-org-protocol/org-protocol-capture-file ()
+  "capture: `org-protocol-sanitize-uri' could distort URL."
+  :expected-result :failed
+  (let* ((org-protocol-default-template-key "t")
+	 (temp-file-name (make-temp-file "org-protocol-test"))
+	 (org-capture-templates
+	  `(("t" "Test" plain (file ,temp-file-name) "%a\n%i\n" :kill-buffer t))))
+    (let ((uri "/org-protocol:/capture:/t/file%3A%2F%2F%2Fetc%2Fmailcap/Triple%20Slash/Body"))
+      (should (null (org-protocol-check-filename-for-protocol uri (list uri) nil)))
+      (should (string= (buffer-string) "[[file:///etc/mailcap][Triple Slash]]\nBody")))
+    (let ((uri "/org-protocol:/capture?template=t&url=file%3A%2F%2F%2Fetc%2Fmailcap&title=Triple%20Slash&body=Body"))
+      (should (null (org-protocol-check-filename-for-protocol uri (list uri) nil)))
+      (should (string= (buffer-string) "[[file:///etc/mailcap][Triple Slash]]\nBody")))))
+
 (ert-deftest test-org-protocol/org-protocol-open-source ()
   "Test org-protocol://open-source links."
   (let* ((temp-file-name1 (make-temp-file "org-protocol-test1"))
-- 
2.25.1




      parent reply	other threads:[~2021-04-04 14:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-04 14:32 Broken org-protocol tests Maxim Nikulin
2021-04-04 14:40 ` [PATCH 1/3] test-org-protocol.el: Fix the case for parse parameters with complex argument Maxim Nikulin
2021-04-04 14:44 ` [PATCH 2/3] org-protocol.el: Fix detection of old-style URIs Maxim Nikulin
2021-04-04 14:44 ` Maxim Nikulin [this message]

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://orgmode.org

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

  git send-email \
    --in-reply-to='s4cjdb$156g$3@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git