Subject: Re: bug#78640: elisp url.el cannot handle some valid URLs

From: Andreas Schwab <[email-masked]>
Date: Mon, 09 Jun 2025 12:01:23 +0200

On Jun 09 2025, Robert Pluim wrote:

> diff --git a/lisp/url/url-http.el b/lisp/url/url-http.el
> index 4258da33a33..5a8279a4122 100644
> --- a/lisp/url/url-http.el
> +++ b/lisp/url/url-http.el
> @@ -325,8 +325,12 @@ url-http-create-request
>  					  url-http-target-url)
>                                           nil 'any nil)))
>           (ref-url (url-http--encode-string url-http-referer)))
> -    (if (equal "" real-fname)
> -	(setq real-fname "/"))
> +    (cond ((equal "" real-fname)
> +	   (setq real-fname "/"))
> +          ;; RFC 3986 section 6.2.3 says an empty path should be
> +          ;; normalized to "/".  (Bug#78640)
> +          ((not (eq (aref real-fname 0) ?/))
> +           (setq real-fname (concat "/" real-fname))))

The two conditions could be combined since (concat "/" real-fname) also
works if real-fname is "".

  (if (not (string-match-p "\\`/" real-fname))
      (setq real-fname (concat "/" real-fname)))

-- 
Andreas Schwab, [email-masked]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."