GNU bug report logs - #68913
[PATCH] Fix browse-url-url-at-point so that scheme does not duplicate

Previous Next

Package: emacs;

Reported by: Kenta USAMI <zonuexe <at> zonu.me>

Date: Sat, 3 Feb 2024 19:19:02 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 68913 in the body.
You can then email your comments to 68913 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#68913; Package emacs. (Sat, 03 Feb 2024 19:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kenta USAMI <zonuexe <at> zonu.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 03 Feb 2024 19:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kenta USAMI <zonuexe <at> zonu.me>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix browse-url-url-at-point so that scheme does not duplicate
Date: Sun, 4 Feb 2024 04:17:29 +0900
[Message part 1 (text/plain, inline)]
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.
[Message part 2 (text/html, inline)]
[0001-Fix-browse-url-url-at-point-so-that-scheme-does-not-.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68913; Package emacs. (Sat, 03 Feb 2024 19:50:02 GMT) Full text and rfc822 format available.

Message #8 received at 68913 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Kenta USAMI <zonuexe <at> zonu.me>
Cc: 68913 <at> debbugs.gnu.org
Subject: Re: bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme does
 not duplicate
Date: Sat, 03 Feb 2024 21:49:33 +0200
> From: Kenta USAMI <zonuexe <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68913; Package emacs. (Sat, 03 Feb 2024 20:49:02 GMT) Full text and rfc822 format available.

Message #11 received at 68913 <at> debbugs.gnu.org (full text, mbox):

From: Kenta USAMI <zonuexe <at> zonu.me>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 68913 <at> debbugs.gnu.org
Subject: Re: bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme
 does not duplicate
Date: Sun, 4 Feb 2024 05:48:27 +0900
[Message part 1 (text/plain, inline)]
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 <at> gnu.org>:

> > From: Kenta USAMI <zonuexe <at> 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.
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68913; Package emacs. (Sat, 03 Feb 2024 21:01:02 GMT) Full text and rfc822 format available.

Message #14 received at 68913 <at> debbugs.gnu.org (full text, mbox):

From: Kenta USAMI <zonuexe <at> zonu.me>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 68913 <at> debbugs.gnu.org
Subject: Re: bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme
 does not duplicate
Date: Sun, 4 Feb 2024 05:59:48 +0900
[Message part 1 (text/plain, inline)]
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 <at> 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 <at> gnu.org>:
>
>> > From: Kenta USAMI <zonuexe <at> 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.
>>
>
[Message part 2 (text/html, inline)]
[foo.el (application/octet-stream, attachment)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Thu, 08 Feb 2024 12:08:01 GMT) Full text and rfc822 format available.

Notification sent to Kenta USAMI <zonuexe <at> zonu.me>:
bug acknowledged by developer. (Thu, 08 Feb 2024 12:08:02 GMT) Full text and rfc822 format available.

Message #19 received at 68913-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Kenta USAMI <zonuexe <at> zonu.me>
Cc: 68913-done <at> debbugs.gnu.org
Subject: Re: bug#68913: [PATCH] Fix browse-url-url-at-point so that scheme
 does not duplicate
Date: Thu, 08 Feb 2024 14:07:03 +0200
> From: Kenta USAMI <zonuexe <at> zonu.me>
> Date: Sun, 4 Feb 2024 05:48:27 +0900
> Cc: 68913 <at> 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.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 07 Mar 2024 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 99 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.