* Bug: protocol capture without url corrupts org-stored-links [9.1.14 (9.1.14-1059-gadec50-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)]
@ 2018-12-12 3:18 Allen Li
2018-12-12 3:38 ` Allen Li
0 siblings, 1 reply; 5+ messages in thread
From: Allen Li @ 2018-12-12 3:18 UTC (permalink / raw)
To: Org Mode List
Using Org protocol capture without supplying a URL inserts a corrupt
entry into org-stored-links (nil ""). The nil causes a type error later
in org-insert-link.
(defun org-protocol-do-capture (info)
"Perform the actual capture based on INFO."
(let* ((temp-parts (org-protocol-parse-parameters info))
(parts
(cond
((and (listp info) (symbolp (car info))) info)
((= (length (car temp-parts)) 1) ;; First parameter is exactly one
character long
(org-protocol-assign-parameters temp-parts '(:template :url :title :body)))
(t
(org-protocol-assign-parameters temp-parts '(:url :title :body)))))
(template (or (plist-get parts :template)
org-protocol-default-template-key))
(url (and (plist-get parts :url) (org-protocol-sanitize-uri (plist-get
parts :url))))
(type (and url (string-match "^\\([a-z]+\\):" url) (match-string 1 url)))
(title (or (plist-get parts :title) ""))
(region (or (plist-get parts :body) ""))
(orglink (if url
(org-make-link-string
url (if (string-match "[^[:space:]]" title) title url))
title))
(org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
(setq org-stored-links
(cons (list url title) org-stored-links))
Emacs : GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
of 2018-07-05
Package: Org mode version 9.1.14 (9.1.14-1059-gadec50-elpaplus @
/home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Bug: protocol capture without url corrupts org-stored-links [9.1.14 (9.1.14-1059-gadec50-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)]
2018-12-12 3:18 Bug: protocol capture without url corrupts org-stored-links [9.1.14 (9.1.14-1059-gadec50-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)] Allen Li
@ 2018-12-12 3:38 ` Allen Li
2018-12-12 16:38 ` Nicolas Goaziou
0 siblings, 1 reply; 5+ messages in thread
From: Allen Li @ 2018-12-12 3:38 UTC (permalink / raw)
To: Org Mode List
[-- Attachment #1: Type: text/plain, Size: 2008 bytes --]
Attached patch
I didn't realize that org-protocol-capture is documented for URLs,
since the concept of capturing through org-protocol is useful for
non-web browser contexts.
Anyway, I'm not interested in updating the documentation for
org-protocol-capture at the moment, but even if org-protocol-capture
is documented to need a URL, it seems wrong for it to corrupt
org-stored-links but otherwise function correctly if a URL was not
provided.
On Tue, Dec 11, 2018 at 7:18 PM Allen Li <darkfeline@felesatra.moe> wrote:
>
> Using Org protocol capture without supplying a URL inserts a corrupt
> entry into org-stored-links (nil ""). The nil causes a type error later
> in org-insert-link.
>
> (defun org-protocol-do-capture (info)
> "Perform the actual capture based on INFO."
> (let* ((temp-parts (org-protocol-parse-parameters info))
> (parts
> (cond
> ((and (listp info) (symbolp (car info))) info)
> ((= (length (car temp-parts)) 1) ;; First parameter is exactly one
> character long
> (org-protocol-assign-parameters temp-parts '(:template :url :title :body)))
> (t
> (org-protocol-assign-parameters temp-parts '(:url :title :body)))))
> (template (or (plist-get parts :template)
> org-protocol-default-template-key))
> (url (and (plist-get parts :url) (org-protocol-sanitize-uri (plist-get
> parts :url))))
> (type (and url (string-match "^\\([a-z]+\\):" url) (match-string 1 url)))
> (title (or (plist-get parts :title) ""))
> (region (or (plist-get parts :body) ""))
> (orglink (if url
> (org-make-link-string
> url (if (string-match "[^[:space:]]" title) title url))
> title))
> (org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
> (setq org-stored-links
> (cons (list url title) org-stored-links))
>
>
> Emacs : GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
> of 2018-07-05
> Package: Org mode version 9.1.14 (9.1.14-1059-gadec50-elpaplus @
> /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)
[-- Attachment #2: 0001-org-protocol-Don-t-corrupt-org-stored-link-if-url-is.patch --]
[-- Type: text/x-patch, Size: 995 bytes --]
From 112ef17dec8aa7dfaba5d6ee0018d8fe3b6639e6 Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Tue, 11 Dec 2018 19:32:56 -0800
Subject: [PATCH] org-protocol: Don't corrupt org-stored-link if url is nil
* lisp/org-protocol.el (org-protocol-do-capture): Handle nil case.
---
lisp/org-protocol.el | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el
index c0eb52c2b..81ab47698 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -503,8 +503,8 @@ Now template ?b will be used."
url (if (string-match "[^[:space:]]" title) title url))
title))
(org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
- (setq org-stored-links
- (cons (list url title) org-stored-links))
+ (when url
+ (push (if (string= title "") (list url) (list url title)) org-stored-links))
(org-store-link-props :type type
:link url
:description title
--
2.20.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Bug: protocol capture without url corrupts org-stored-links [9.1.14 (9.1.14-1059-gadec50-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)]
2018-12-12 3:38 ` Allen Li
@ 2018-12-12 16:38 ` Nicolas Goaziou
2018-12-12 22:59 ` Allen Li
0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2018-12-12 16:38 UTC (permalink / raw)
To: Allen Li; +Cc: Org Mode List
Hello,
Allen Li <darkfeline@felesatra.moe> writes:
> I didn't realize that org-protocol-capture is documented for URLs,
> since the concept of capturing through org-protocol is useful for
> non-web browser contexts.
>
> Anyway, I'm not interested in updating the documentation for
> org-protocol-capture at the moment, but even if org-protocol-capture
> is documented to need a URL, it seems wrong for it to corrupt
> org-stored-links but otherwise function correctly if a URL was not
> provided.
Could you give more context about the bug you're encountering? What does
mean "function correctly if a URL was not provided"? What is the use
case? What result did you expect, besides not encountering an error
message?
There are multiple ways to solve this. In particular, if a URL is not
provided, it seems natural to store nil instead, as
`org-protocol-capture' currently does. If we do not support missing URL,
then it should raise an error instead of letting it slip into
`org-insert-link'. If we do, then `org-insert-link' should handle it
gracefully.
So, again, more context could help understanding what is the best
solution.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Bug: protocol capture without url corrupts org-stored-links [9.1.14 (9.1.14-1059-gadec50-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)]
2018-12-12 16:38 ` Nicolas Goaziou
@ 2018-12-12 22:59 ` Allen Li
2018-12-18 8:34 ` Nicolas Goaziou
0 siblings, 1 reply; 5+ messages in thread
From: Allen Li @ 2018-12-12 22:59 UTC (permalink / raw)
To: Org Mode List
On Wed, Dec 12, 2018 at 9:59 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>
> Could you give more context about the bug you're encountering? What does
> mean "function correctly if a URL was not provided"? What is the use
> case? What result did you expect, besides not encountering an error
> message?
The issue occurs when org protocol capture is invoked without a url param, e.g.
emacsclient 'org-protocol://capture?url=percent-encoded-url&body=some-text'
vs
emacsclient 'org-protocol://capture?body=some-text'
By "function correctly", I mean make the latter not break
org-insert-link by not corrupting the value of org-stored-links.
The use case is capturing some text without an associated URL.
The result I expect is the latter not breaking org-insert-link.
Note that invoking the latter otherwise behaves correctly/as expected.
It starts the capture process with the provided body text/initial
contents. The only thing that breaks is org-insert-link when the user
calls org-insert-link later.
> There are multiple ways to solve this. In particular, if a URL is not
> provided, it seems natural to store nil instead, as
> `org-protocol-capture' currently does. If we do not support missing URL,
> then it should raise an error instead of letting it slip into
> `org-insert-link'. If we do, then `org-insert-link' should handle it
> gracefully.
Except storing nil is not supported by org-insert-link, breaking it
until the savvy user manually fixes org-stored-links. I don't see
what meaning storing and inserting a nil link could have.
We could change org-insert-link to fix or ignore the invalid value in
org-stored-links, but why not stop inserting the invalid value into
org-stored-links in the first place?
>
> So, again, more context could help understanding what is the best
> solution.
>
> Regards,
>
> --
> Nicolas Goaziou
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Bug: protocol capture without url corrupts org-stored-links [9.1.14 (9.1.14-1059-gadec50-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)]
2018-12-12 22:59 ` Allen Li
@ 2018-12-18 8:34 ` Nicolas Goaziou
0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2018-12-18 8:34 UTC (permalink / raw)
To: Allen Li; +Cc: Org Mode List
Hello,
Allen Li <darkfeline@felesatra.moe> writes:
> On Wed, Dec 12, 2018 at 9:59 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>>
>> Could you give more context about the bug you're encountering? What does
>> mean "function correctly if a URL was not provided"? What is the use
>> case? What result did you expect, besides not encountering an error
>> message?
>
> The issue occurs when org protocol capture is invoked without a url param, e.g.
>
> emacsclient 'org-protocol://capture?url=percent-encoded-url&body=some-text'
>
> vs
>
> emacsclient 'org-protocol://capture?body=some-text'
>
> By "function correctly", I mean make the latter not break
> org-insert-link by not corrupting the value of org-stored-links.
>
> The use case is capturing some text without an associated URL.
Fixed. Thank you.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-12-18 8:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-12 3:18 Bug: protocol capture without url corrupts org-stored-links [9.1.14 (9.1.14-1059-gadec50-elpaplus @ /home/ionasal/.emacs.d/elpa/org-plus-contrib-20181211/)] Allen Li
2018-12-12 3:38 ` Allen Li
2018-12-12 16:38 ` Nicolas Goaziou
2018-12-12 22:59 ` Allen Li
2018-12-18 8:34 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.