This is an automated email from the git hooks/post-receive script.

arnebab pushed a commit to branch main
in repository guile.

The following commit(s) were added to refs/heads/main by this push:
     new 29c27afe9 Allow trailing "." in urls
29c27afe9 is described below

commit 29c27afe96ac6eccc42607be57c285ba912af28f
Author: Dale P. Smith <dalepsm...@gmail.com>
AuthorDate: Thu Jan 27 19:20:57 2022 -0500

    Allow trailing "." in urls
    
    Fixes https://debbugs.gnu.org/53201
    
    * module/web/uri.scm (valid-host?): Allow trailing "." in URLs
    * test-suite/tests/web-uri.test: Add tests for trailing "."
---
 module/web/uri.scm            | 17 ++++++++++-------
 test-suite/tests/web-uri.test | 10 ++++++++++
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/module/web/uri.scm b/module/web/uri.scm
index 8e0b9bee7..8c5c0d6f0 100644
--- a/module/web/uri.scm
+++ b/module/web/uri.scm
@@ -206,13 +206,16 @@ for ‘build-uri’ except there is no scheme."
    ((regexp-exec ipv6-regexp host)
     (false-if-exception (inet-pton AF_INET6 host)))
    (else
-    (let lp ((start 0))
-      (let ((end (string-index host #\. start)))
-        (if end
-            (and (regexp-exec domain-label-regexp
-                              (substring host start end))
-                 (lp (1+ end)))
-            (regexp-exec top-label-regexp host start)))))))
+    (let ((last (1- (string-length host))))
+      (let lp ((start 0))
+        (let ((end (string-index host #\. start)))
+          (if (and end (< end last))
+              (and (regexp-exec domain-label-regexp
+                                (substring host start end))
+                   (lp (1+ end)))
+              (if end
+                  (regexp-exec top-label-regexp (substring host start end))
+                  (regexp-exec top-label-regexp host start)))))))))
 
 (define userinfo-pat
   (string-append "[" letters digits "_.!~*'();:&=+$,-]+"))
diff --git a/test-suite/tests/web-uri.test b/test-suite/tests/web-uri.test
index 95fd82f16..e9fb766f0 100644
--- a/test-suite/tests/web-uri.test
+++ b/test-suite/tests/web-uri.test
@@ -367,6 +367,16 @@
   (pass-if "//bad.host.1"
     (not (string->uri-reference "//bad.host.1")))
 
+  (pass-if "//bad.host.1."
+    (not (string->uri-reference "//bad.host.1.")))
+
+  (pass-if "//bad.host.."
+    (not (string->uri-reference "//bad.host..")))
+
+  (pass-if "//1.good.host."
+    (uri=? (string->uri-reference "//1.good.host.")
+           #:host "1.good.host." #:path ""))
+
   (pass-if "http://1.good.host";
     (uri=? (string->uri-reference "http://1.good.host";)
            #:scheme 'http #:host "1.good.host" #:path ""))

Reply via email to