all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate
@ 2024-02-03 19:17 Kenta USAMI
  2024-02-03 19:49 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Kenta USAMI @ 2024-02-03 19:17 UTC (permalink / raw)
  To: 68913


[-- Attachment #1.1: Type: text/plain, Size: 948 bytes --]

Hi,

In the text below, move point to the second half of the URL and
execute M-x browse-url-at-point.

```
[![Emacs](
https://www.gnu.org/software/emacs/images/emacs.png)](https://www.gnu.org/software/emacs/download.html
)
```

Firefox and Chromium-based browsers appear to open the URL "https//
www.gnu.org/software/emacs/download.html".
It seems that the ":" following https is deleted, but the browser actually
normalizes
the URL with the duplicate scheme "http://https://".

You can check this by executing M-: (browse-url-url-at-point).

Because thing-at-point-bounds-of-url-at-point function cannot correctly
recognize
URL bounds in the text.

I considered changing the thing-at-point-bounds-of-url-at-point algorithm,
but it would be a pain to change it without negatively impacting the
current behavior.
Ideally, thing-at-point-bounds-of-url-at-point will be fixed eventually,
but for now, the attached patch should easily fix the problem.

[-- Attachment #1.2: Type: text/html, Size: 1424 bytes --]

[-- Attachment #2: 0001-Fix-browse-url-url-at-point-so-that-scheme-does-not-.patch --]
[-- Type: application/octet-stream, Size: 1079 bytes --]

From 09082305dbe87620657cf9d6c3fe0c058deee800 Mon Sep 17 00:00:00 2001
From: USAMI Kenta <tadsan@zonu.me>
Date: Sun, 4 Feb 2024 03:20:24 +0900
Subject: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate

---
 lisp/net/browse-url.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index 359453ca43..bc2a7db9a8 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -688,8 +688,10 @@ browse-url-default-scheme
 (defun browse-url-url-at-point ()
   (or (thing-at-point 'url t)
       ;; assume that the user is pointing at something like gnu.org/gnu
-      (let ((f (thing-at-point 'filename t)))
-        (and f (concat browse-url-default-scheme "://" f)))))
+      (when-let ((f (thing-at-point 'filename t)))
+	(if (string-match-p browse-url-button-regexp f)
+	    f
+	  (concat browse-url-default-scheme "://" f)))))
 
 ;; Having this as a separate function called by the browser-specific
 ;; functions allows them to be stand-alone commands, making it easier
-- 
2.43.0


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

* bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate
  2024-02-03 19:17 bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate Kenta USAMI
@ 2024-02-03 19:49 ` Eli Zaretskii
  2024-02-03 20:48   ` Kenta USAMI
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-02-03 19:49 UTC (permalink / raw)
  To: Kenta USAMI; +Cc: 68913

> From: Kenta USAMI <zonuexe@zonu.me>
> Date: Sun, 4 Feb 2024 04:17:29 +0900
> 
> In the text below, move point to the second half of the URL and
> execute M-x browse-url-at-point.
> 
> ```
> [![Emacs](
> https://www.gnu.org/software/emacs/images/emacs.png)](https://www.gnu.org/software/emacs/download.html
> )
> ```
> 
> Firefox and Chromium-based browsers appear to open the URL "https//
> www.gnu.org/software/emacs/download.html".
> It seems that the ":" following https is deleted, but the browser actually
> normalizes
> the URL with the duplicate scheme "http://https://".

In what version of Emacs did you see that?  And on what OS?

Also, please post a complete recipe: do I type the above into the
*scratch* buffer, or into some other buffer, and what should be the
major-mode of that buffer?  Also, is the part inside [...] that
precedes the URL important for reproducing the problem?

Thanks.





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

* bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate
  2024-02-03 19:49 ` Eli Zaretskii
@ 2024-02-03 20:48   ` Kenta USAMI
  2024-02-03 20:59     ` Kenta USAMI
  2024-02-08 12:07     ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Kenta USAMI @ 2024-02-03 20:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 68913

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

I'm using Emacs 29.2 on macOS.
GNU Emacs 29.2 (build 2, aarch64-apple-darwin23.3.0, NS appkit-2487.40
Version 14.3 (Build 23D56))
 of 2024-01-26

This problem is most noticeable when using markdown-mode and
goto-address-mode,
but it also seems to occur even if goto-address-mode is disabled in
text-mode or fundamental-mode.

You can see the problem by evaluating the Lisp code below.

;;; foo.el
(require 'ert)
(require 'browse-url)

(ert-deftest test-browse-url-url-at-point ()
  (let* ((text "
[![Emacs](
https://www.gnu.org/software/emacs/images/emacs.png)](https://www.gnu.org/software/emacs/download.html
)
")
         (expected "https://www.gnu.org/software/emacs/download.html")
         (actual (with-temp-buffer
                   (insert text)
                   (goto-char 76)
                   (browse-url-url-at-point))))
    (should (string= expected actual))))

Evaluate the expression directly in the buffer or save it to a file and
check it with the command below.

$ emacs --batch -l foo.el -f ert-run-tests-batch-and-exit

2024年2月4日(日) 4:49 Eli Zaretskii <eliz@gnu.org>:

> > From: Kenta USAMI <zonuexe@zonu.me>
> > Date: Sun, 4 Feb 2024 04:17:29 +0900
> >
> > In the text below, move point to the second half of the URL and
> > execute M-x browse-url-at-point.
> >
> > ```
> > [![Emacs](
> >
> https://www.gnu.org/software/emacs/images/emacs.png)](https://www.gnu.org/software/emacs/download.html
> > )
> > ```
> >
> > Firefox and Chromium-based browsers appear to open the URL "https//
> > www.gnu.org/software/emacs/download.html".
> > It seems that the ":" following https is deleted, but the browser
> actually
> > normalizes
> > the URL with the duplicate scheme "http://https://".
>
> In what version of Emacs did you see that?  And on what OS?
>
> Also, please post a complete recipe: do I type the above into the
> *scratch* buffer, or into some other buffer, and what should be the
> major-mode of that buffer?  Also, is the part inside [...] that
> precedes the URL important for reproducing the problem?
>
> Thanks.
>

[-- Attachment #2: Type: text/html, Size: 3241 bytes --]

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

* bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate
  2024-02-03 20:48   ` Kenta USAMI
@ 2024-02-03 20:59     ` Kenta USAMI
  2024-02-08 12:07     ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Kenta USAMI @ 2024-02-03 20:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 68913


[-- Attachment #1.1: Type: text/plain, Size: 2432 bytes --]

I forgot that MUA can insert newlines on long lines.

Resend the test code to the URL and attachment below.
https://gitlab.com/-/snippets/3650077

2024年2月4日(日) 5:48 Kenta USAMI <zonuexe@zonu.me>:

> I'm using Emacs 29.2 on macOS.
> GNU Emacs 29.2 (build 2, aarch64-apple-darwin23.3.0, NS appkit-2487.40
> Version 14.3 (Build 23D56))
>  of 2024-01-26
>
> This problem is most noticeable when using markdown-mode and
> goto-address-mode,
> but it also seems to occur even if goto-address-mode is disabled in
> text-mode or fundamental-mode.
>
> You can see the problem by evaluating the Lisp code below.
>
> ;;; foo.el
> (require 'ert)
> (require 'browse-url)
>
> (ert-deftest test-browse-url-url-at-point ()
>   (let* ((text "
> [![Emacs](
> https://www.gnu.org/software/emacs/images/emacs.png)](https://www.gnu.org/software/emacs/download.html
> )
> ")
>          (expected "https://www.gnu.org/software/emacs/download.html")
>          (actual (with-temp-buffer
>                    (insert text)
>                    (goto-char 76)
>                    (browse-url-url-at-point))))
>     (should (string= expected actual))))
>
> Evaluate the expression directly in the buffer or save it to a file and
> check it with the command below.
>
> $ emacs --batch -l foo.el -f ert-run-tests-batch-and-exit
>
> 2024年2月4日(日) 4:49 Eli Zaretskii <eliz@gnu.org>:
>
>> > From: Kenta USAMI <zonuexe@zonu.me>
>> > Date: Sun, 4 Feb 2024 04:17:29 +0900
>> >
>> > In the text below, move point to the second half of the URL and
>> > execute M-x browse-url-at-point.
>> >
>> > ```
>> > [![Emacs](
>> >
>> https://www.gnu.org/software/emacs/images/emacs.png)](https://www.gnu.org/software/emacs/download.html
>> > )
>> > ```
>> >
>> > Firefox and Chromium-based browsers appear to open the URL "https//
>> > www.gnu.org/software/emacs/download.html".
>> > It seems that the ":" following https is deleted, but the browser
>> actually
>> > normalizes
>> > the URL with the duplicate scheme "http://https://".
>>
>> In what version of Emacs did you see that?  And on what OS?
>>
>> Also, please post a complete recipe: do I type the above into the
>> *scratch* buffer, or into some other buffer, and what should be the
>> major-mode of that buffer?  Also, is the part inside [...] that
>> precedes the URL important for reproducing the problem?
>>
>> Thanks.
>>
>

[-- Attachment #1.2: Type: text/html, Size: 3843 bytes --]

[-- Attachment #2: foo.el --]
[-- Type: application/octet-stream, Size: 480 bytes --]

(require 'ert)
(require 'browse-url)

(ert-deftest test-browse-url-url-at-point ()
  (let* ((text "
[![Emacs](https://www.gnu.org/software/emacs/images/emacs.png)](https://www.gnu.org/software/emacs/download.html)
")
         (expected "https://www.gnu.org/software/emacs/download.html")
         (actual (with-temp-buffer
                   (insert text)
                   (goto-char 76)
                   (browse-url-url-at-point))))
    (should (string= expected actual))))


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

* bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate
  2024-02-03 20:48   ` Kenta USAMI
  2024-02-03 20:59     ` Kenta USAMI
@ 2024-02-08 12:07     ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2024-02-08 12:07 UTC (permalink / raw)
  To: Kenta USAMI; +Cc: 68913-done

> From: Kenta USAMI <zonuexe@zonu.me>
> Date: Sun, 4 Feb 2024 05:48:27 +0900
> Cc: 68913@debbugs.gnu.org
> 
> I'm using Emacs 29.2 on macOS.
> GNU Emacs 29.2 (build 2, aarch64-apple-darwin23.3.0, NS appkit-2487.40 Version 14.3 (Build 23D56))
>  of 2024-01-26
> 
> This problem is most noticeable when using markdown-mode and goto-address-mode, 
> but it also seems to occur even if goto-address-mode is disabled in text-mode or fundamental-mode.
> 
> You can see the problem by evaluating the Lisp code below.

Thanks, I installed your patch on the master branch, and I'm closing
this bug.





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

end of thread, other threads:[~2024-02-08 12:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-03 19:17 bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate Kenta USAMI
2024-02-03 19:49 ` Eli Zaretskii
2024-02-03 20:48   ` Kenta USAMI
2024-02-03 20:59     ` Kenta USAMI
2024-02-08 12:07     ` Eli Zaretskii

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.