emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Additonal slashes in URI sent to org-protocol
@ 2020-04-05 13:56 Ferdinand Pieper
  0 siblings, 0 replies; 5+ messages in thread
From: Ferdinand Pieper @ 2020-04-05 13:56 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi everyone,

I was trying to set up org-protocol with Firefox (version 74.0) running under Windows 10. Unfortunately there seems to be an issue with additional slashes added to the URI so org-protocol can not parse it.

I setup a bookmark as mentioned in [1]. I changed the bookmark content to the new style of org-protocol links as described in [2], resulting in:

--8<---------------cut here---------------start------------->8---
javascript:location.href='org-protocol://capture?template=L&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(window.getSelection())
--8<---------------cut here---------------end--------------->8---

To setup the forwarding to Emacs running inside WSL I used a registry entry as described on the same page:

--8<---------------cut here---------------start------------->8---
REGEDIT4

[HKEY_CLASSES_ROOT\org-protocol]
@="URL:Org Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\org-protocol\shell]
[HKEY_CLASSES_ROOT\org-protocol\shell\open]
[HKEY_CLASSES_ROOT\org-protocol\shell\open\command]
@="\"C:\\Windows\\System32\\wsl.exe\" emacsclient \"%1\""
--8<---------------cut here---------------end--------------->8---

Somehow Firefox adds another slash inbetween ~capture~ and the questionmark, so that Emacs receives this call, which I extracted from a Backtrace:

--8<---------------cut here---------------start------------->8---
* org-protocol-check-filename-for-protocol("/mnt/c/Windows/system32/org-protocol:/capture/?template=L&url=https%3A%2F%2Forgmode.org%2F&title=Org%20mode%20for%20Emacs%20–%20Your%20Life%20in%20Plain%20Text&body=" (("/mnt/c/Windows/system32/org-protocol:/capture/?template=L&url=https%3A%2F%2Forgmode.org%2F&title=Org%20mode%20for%20Emacs%20–%20Your%20Life%20in%20Plain%20Text&body=")) #<process server 
<68>>)
--8<---------------cut here---------------end--------------->8---

The format ~org-protocol:/capture/?template=L...~ still seems to be within the HTML spec. But the additional slash makes the function ~org-protocol-check-filename-for-protocol~ fail to recognize the URI as a capture call. See also the discussion in [3].
I also tried the same bookmark in Chromium (version 83.0) but it also adds the additional slash.
I attached a proposed patch to allow URIs with and without the slash.

I'd be happy to know if anybody has a working setup using the bookmark above or similar or if there are other solutions which do not require this patch. Otherwise please let me know what is left to do to get this patch applied.

Thanks!


Footnotes:
[1]  https://orgmode.org/worg/org-contrib/org-protocol.html#org120a44e

[2]  https://orgmode.org/Changes_old.html#org18864d9

[3] https://github.com/sprig/org-capture-extension/issues/41#issuecomment-578499266


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-protocol-Allow-slashes-after-sub-protocol.patch --]
[-- Type: text/x-patch, Size: 1432 bytes --]

From a476821ebecd9649b2c88a86a0562c757bb2c3a0 Mon Sep 17 00:00:00 2001
From: fpi <git@pie.tf>
Date: Fri, 3 Apr 2020 19:12:01 +0200
Subject: [PATCH] org-protocol: Allow slashes after sub-protocol

This change lets org-protocol handle URIs with additional slashes
before the start of the query string, e.g.

org-protocol:/capture/?template=...

instead of

org-protocol:/capture?template=...
---
 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 55a534d0d..8fbff9611 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -617,13 +617,13 @@ CLIENT is ignored."
             (let ((proto
 		   (concat the-protocol
 			   (regexp-quote (plist-get (cdr prolist) :protocol))
-			   "\\(:/+\\|\\?\\)")))
+			   "\\(:/+\\|/*\\?\\)")))
               (when (string-match proto fname)
                 (let* ((func (plist-get (cdr prolist) :function))
                        (greedy (plist-get (cdr prolist) :greedy))
                        (split (split-string fname proto))
                        (result (if greedy restoffiles (cadr split)))
-		       (new-style (string= (match-string 1 fname) "?")))
+		       (new-style (string-match (match-string 1 fname) "/*?")))
                   (when (plist-get (cdr prolist) :kill-client)
 		    (message "Greedy org-protocol handler.  Killing client.")
 		    (server-edit))
-- 
2.25.0


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

* Additonal slashes in URI sent to org-protocol
@ 2020-04-05 14:55 Ferdinand Pieper
  2020-05-06  1:04 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Ferdinand Pieper @ 2020-04-05 14:55 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi everyone,

I was trying to set up org-protocol with Firefox (version 74.0) running under Windows 10. Unfortunately there seems to be an issue with additional slashes added to the URI so org-protocol can not parse it.

I setup a bookmark as mentioned in [1]. I changed the bookmark content to the new style of org-protocol links as described in [2], resulting in:

--8<---------------cut here---------------start------------->8---
javascript:location.href='org-protocol://capture?template=L&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(window.getSelection())
--8<---------------cut here---------------end--------------->8---

To setup the forwarding to Emacs running inside WSL I used a registry entry as described on the same page:

--8<---------------cut here---------------start------------->8---
REGEDIT4

[HKEY_CLASSES_ROOT\org-protocol]
@="URL:Org Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\org-protocol\shell]
[HKEY_CLASSES_ROOT\org-protocol\shell\open]
[HKEY_CLASSES_ROOT\org-protocol\shell\open\command]
@="\"C:\\Windows\\System32\\wsl.exe\" emacsclient \"%1\""
--8<---------------cut here---------------end--------------->8---

Somehow Firefox adds another slash inbetween ~capture~ and the questionmark, so that Emacs receives this call, which I extracted from a Backtrace:

--8<---------------cut here---------------start------------->8---
* org-protocol-check-filename-for-protocol("/mnt/c/Windows/system32/org-protocol:/capture/?template=L&url=https%3A%2F%2Forgmode.org%2F&title=Org%20mode%20for%20Emacs%20–%20Your%20Life%20in%20Plain%20Text&body=" (("/mnt/c/Windows/system32/org-protocol:/capture/?template=L&url=https%3A%2F%2Forgmode.org%2F&title=Org%20mode%20for%20Emacs%20–%20Your%20Life%20in%20Plain%20Text&body=")) #<process server 
<68>>)
--8<---------------cut here---------------end--------------->8---

The format ~org-protocol:/capture/?template=L...~ still seems to be within the HTML spec. But the additional slash makes the function ~org-protocol-check-filename-for-protocol~ fail to recognize the URI as a capture call. See also the discussion in [3].
I also tried the same bookmark in Chromium (version 83.0) but it also adds the additional slash.
I attached a proposed patch to allow URIs with and without the slash.

I'd be happy to know if anybody has a working setup using the bookmark above or similar or if there are other solutions which do not require this patch. Otherwise please let me know what is left to do to get this patch applied.

Thanks!


Footnotes:
[1]  https://orgmode.org/worg/org-contrib/org-protocol.html#org120a44e

[2]  https://orgmode.org/Changes_old.html#org18864d9

[3] https://github.com/sprig/org-capture-extension/issues/41#issuecomment-578499266


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-protocol-Allow-slashes-after-sub-protocol.patch --]
[-- Type: text/x-patch, Size: 1432 bytes --]

From a476821ebecd9649b2c88a86a0562c757bb2c3a0 Mon Sep 17 00:00:00 2001
From: fpi <git@pie.tf>
Date: Fri, 3 Apr 2020 19:12:01 +0200
Subject: [PATCH] org-protocol: Allow slashes after sub-protocol

This change lets org-protocol handle URIs with additional slashes
before the start of the query string, e.g.

org-protocol:/capture/?template=...

instead of

org-protocol:/capture?template=...
---
 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 55a534d0d..8fbff9611 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -617,13 +617,13 @@ CLIENT is ignored."
             (let ((proto
 		   (concat the-protocol
 			   (regexp-quote (plist-get (cdr prolist) :protocol))
-			   "\\(:/+\\|\\?\\)")))
+			   "\\(:/+\\|/*\\?\\)")))
               (when (string-match proto fname)
                 (let* ((func (plist-get (cdr prolist) :function))
                        (greedy (plist-get (cdr prolist) :greedy))
                        (split (split-string fname proto))
                        (result (if greedy restoffiles (cadr split)))
-		       (new-style (string= (match-string 1 fname) "?")))
+		       (new-style (string-match (match-string 1 fname) "/*?")))
                   (when (plist-get (cdr prolist) :kill-client)
 		    (message "Greedy org-protocol handler.  Killing client.")
 		    (server-edit))
-- 
2.25.0


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

* Re: Additonal slashes in URI sent to org-protocol
  2020-04-05 14:55 Additonal slashes in URI sent to org-protocol Ferdinand Pieper
@ 2020-05-06  1:04 ` Nicolas Goaziou
  2020-05-09 13:07   ` Ferdinand Pieper
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2020-05-06  1:04 UTC (permalink / raw)
  To: Ferdinand Pieper; +Cc: emacs-orgmode

Hello,

Ferdinand Pieper <list_gnu@pie.tf> writes:

> Subject: [PATCH] org-protocol: Allow slashes after sub-protocol

Thank you.

Please add the function modified in the commit message. Also, if you
haven't signed FSF papers for copyright, you need to insert TINYCHANGE.

> This change lets org-protocol handle URIs with additional slashes
> before the start of the query string, e.g.
>
> org-protocol:/capture/?template=...
>
> instead of
>
> org-protocol:/capture?template=...
> ---
>  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 55a534d0d..8fbff9611 100644
> --- a/lisp/org-protocol.el
> +++ b/lisp/org-protocol.el
> @@ -617,13 +617,13 @@ CLIENT is ignored."
>              (let ((proto
>  		   (concat the-protocol
>  			   (regexp-quote (plist-get (cdr prolist) :protocol))
> -			   "\\(:/+\\|\\?\\)")))
> +			   "\\(:/+\\|/*\\?\\)")))
>                (when (string-match proto fname)
>                  (let* ((func (plist-get (cdr prolist) :function))
>                         (greedy (plist-get (cdr prolist) :greedy))
>                         (split (split-string fname proto))
>                         (result (if greedy restoffiles (cadr split)))
> -		       (new-style (string= (match-string 1 fname) "?")))
> +		       (new-style (string-match (match-string 1 fname) "/*?")))

I don't understand this line. Aren't you calling string-match backwards?
I think you mean:

  (new-style (string-match "?" (match-string 1 fname)))

Could you also insert a comment explaining why this workaround is
required?

Regards,

-- 
Nicolas Goaziou


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

* Re: Additonal slashes in URI sent to org-protocol
  2020-05-06  1:04 ` Nicolas Goaziou
@ 2020-05-09 13:07   ` Ferdinand Pieper
  2020-05-22 15:56     ` Bastien
  0 siblings, 1 reply; 5+ messages in thread
From: Ferdinand Pieper @ 2020-05-09 13:07 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

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

Hey,

thanks for your reply!

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Please add the function modified in the commit message. Also, if 
> you haven't signed FSF papers for copyright, you need to insert 
> TINYCHANGE. 

Done.

>> -		       (new-style (string= (match-string 1 fname) 
>> "?")))  +		       (new-style (string-match 
>> (match-string 1 fname) "/*?"))) 
> 
> I don't understand this line. Aren't you calling string-match 
> backwards?  I think you mean: 
> 
>   (new-style (string-match "?" (match-string 1 fname))) 

Yes, you are right. I mixed this up because I just changed the 
previous line without thinking about it.

> Could you also insert a comment explaining why this workaround 
> is required? 

I added a short comment in the commit message. Did you mean to 
also insert a comment in the code?


Thanks!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-protocol-Allow-slashes-after-sub-protocol.patch --]
[-- Type: text/x-patch, Size: 1599 bytes --]

From ba0ce2837867dac20baa433b15c34cb9d4729e67 Mon Sep 17 00:00:00 2001
From: fpi <git@pie.tf>
Date: Fri, 3 Apr 2020 19:12:01 +0200
Subject: [PATCH] org-protocol: Allow slashes after sub-protocol

* lisp/org-protocol.el (org-protocol-check-filename-for-protocol): Let
org-protocol handle URIs with additional slashes before the start of
the query string, e.g.

org-protocol:/capture/?template=...

instead of

org-protocol:/capture?template=...

This is needed to support some browsers under windows which insert the
additional slash in the URI.

TINYCHANGE
---
 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 55a534d0d..35e1bc2f8 100644
--- a/lisp/org-protocol.el
+++ b/lisp/org-protocol.el
@@ -617,13 +617,13 @@ CLIENT is ignored."
             (let ((proto
 		   (concat the-protocol
 			   (regexp-quote (plist-get (cdr prolist) :protocol))
-			   "\\(:/+\\|\\?\\)")))
+			   "\\(:/+\\|/*\\?\\)")))
               (when (string-match proto fname)
                 (let* ((func (plist-get (cdr prolist) :function))
                        (greedy (plist-get (cdr prolist) :greedy))
                        (split (split-string fname proto))
                        (result (if greedy restoffiles (cadr split)))
-		       (new-style (string= (match-string 1 fname) "?")))
+		       (new-style (string-match "/*?" (match-string 1 fname))))
                   (when (plist-get (cdr prolist) :kill-client)
 		    (message "Greedy org-protocol handler.  Killing client.")
 		    (server-edit))
-- 
2.26.2


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

* Re: Additonal slashes in URI sent to org-protocol
  2020-05-09 13:07   ` Ferdinand Pieper
@ 2020-05-22 15:56     ` Bastien
  0 siblings, 0 replies; 5+ messages in thread
From: Bastien @ 2020-05-22 15:56 UTC (permalink / raw)
  To: Ferdinand Pieper; +Cc: emacs-orgmode, Nicolas Goaziou

Hi Ferdinand,

thanks for your patch, I applied it against master:
https://code.orgmode.org/bzg/org-mode/commit/928e67df7e

I slightly condensed the commit message and I don't think
there is a real need for a comment in the code, but why not.

Cheers,

-- 
 Bastien


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

end of thread, other threads:[~2020-05-22 15:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-05 14:55 Additonal slashes in URI sent to org-protocol Ferdinand Pieper
2020-05-06  1:04 ` Nicolas Goaziou
2020-05-09 13:07   ` Ferdinand Pieper
2020-05-22 15:56     ` Bastien
  -- strict thread matches above, loose matches on Subject: below --
2020-04-05 13:56 Ferdinand Pieper

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