all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Martin Jerabek <om@mailservice.ms>
To: 58718@debbugs.gnu.org
Subject: bug#58718: Acknowledgement (Incorrect regex in nXML URI check)
Date: Sun, 23 Oct 2022 12:46:18 +0200	[thread overview]
Message-ID: <0eae90fa905f352731ef7e26ba02d390b4f9329e.camel@fastmail.fm> (raw)
In-Reply-To: <handler.58718.B.16664517395858.ack@debbugs.gnu.org>

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

It turned out that my patch was incomplete. Fixing the bug in
rng-uri-file-name-1 revealed another bug in rng-uri-unescape-unibyte.
The anonymous function passed to replace-regexp-in-string returned a
number (e.g. 32 for space) but replace-regexp-in-string expected a
string as the return value.

I therefore added a call to "string" to convert the number back to a
string (e.g. " ").

With this fix I was finally able to use a RELAX-NG schema file in a
path containing spaces.

I made the same fix in rng-uri-unescape-unibyte-match because it was
also obviously wrong (regexp-quote expects a string). However,
it would be good if someone more familiar with this code (and Lisp in
general) could check all the other occurrences of
replace-regexp-in-string to make sure they do not contain the same bug.

Find attached the expanded patch.


[-- Attachment #2: rng-uri.patch --]
[-- Type: text/x-patch, Size: 1188 bytes --]

diff --git a/lisp/nxml/rng-uri.el b/lisp/nxml/rng-uri.el
index 77fed8c32d..242238e0d1 100644
--- a/lisp/nxml/rng-uri.el
+++ b/lisp/nxml/rng-uri.el
@@ -68,7 +68,7 @@ Signal an error if URI is not a valid file URL."
 
 ;; pattern is either nil or match or replace
 (defun rng-uri-file-name-1 (uri pattern)
-  (unless (string-match "\\`\\(?:[^%]\\|%[[:xdigit:]]{2}\\)*\\'" uri)
+  (unless (string-match "\\`\\(?:[^%]\\|%[[:xdigit:]]\\{2\\}\\)*\\'" uri)
     (rng-uri-error "Bad escapes in URI `%s'" uri))
   (setq uri (rng-uri-unescape-multibyte uri))
   (let* ((components
@@ -312,7 +312,7 @@ Both FULL and BASE must be absolute URIs."
 (defun rng-uri-unescape-unibyte (str)
   (replace-regexp-in-string "%[0-7][[:xdigit:]]"
 			    (lambda (h)
-			      (string-to-number (substring h 1) 16))
+			      (string (string-to-number (substring h 1) 16)))
 			    str
 			    t
 			    t))
@@ -325,8 +325,8 @@ Both FULL and BASE must be absolute URIs."
 				(regexp-quote
 				 (if (= (length match) 1)
 				     match
-				   (string-to-number (substring match 1)
-						     16)))))
+				   (string (string-to-number (substring match 1)
+						     16))))))
 			    str
 			    t
 			    t))

  parent reply	other threads:[~2022-10-23 10:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-22 12:58 bug#58718: Incorrect regex in nXML URI check Martin Jerabek
     [not found] ` <handler.58718.B.16664517395858.ack@debbugs.gnu.org>
2022-10-23 10:46   ` Martin Jerabek [this message]
2022-10-24 10:51 ` Mattias Engdegård
2022-10-24 12:26   ` Robert Pluim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0eae90fa905f352731ef7e26ba02d390b4f9329e.camel@fastmail.fm \
    --to=om@mailservice.ms \
    --cc=58718@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.