1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Merge from stable-2.2

This commit is contained in:
Andy Wingo 2019-08-02 14:32:35 +02:00
commit 6a102205da
2 changed files with 51 additions and 13 deletions

View file

@ -1,6 +1,6 @@
;;;; (web uri) --- URI manipulation tools ;;;; (web uri) --- URI manipulation tools
;;;; ;;;;
;;;; Copyright (C) 1997,2001,2002,2010,2011,2012,2013,2014 Free Software Foundation, Inc. ;;;; Copyright (C) 1997,2001,2002,2010,2011,2012,2013,2014,2019 Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -175,17 +175,28 @@ for build-uri except there is no scheme."
;;; Converters. ;;; Converters.
;;; ;;;
;; Since character ranges in regular expressions may depend on the
;; current locale, we use explicit lists of characters instead. See
;; <https://bugs.gnu.org/35785> for details.
(define digits "0123456789")
(define hex-digits "0123456789ABCDEFabcdef")
(define letters "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
;; See RFC 3986 #3.2.2 for comments on percent-encodings, IDNA (RFC ;; See RFC 3986 #3.2.2 for comments on percent-encodings, IDNA (RFC
;; 3490), and non-ASCII host names. ;; 3490), and non-ASCII host names.
;; ;;
(define ipv4-regexp (define ipv4-regexp
(make-regexp "^([0-9.]+)$")) (make-regexp (string-append "^([" digits ".]+)$")))
(define ipv6-regexp (define ipv6-regexp
(make-regexp "^([0-9a-fA-F:.]+)$")) (make-regexp (string-append "^([" hex-digits ":.]+)$")))
(define domain-label-regexp (define domain-label-regexp
(make-regexp "^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$")) (make-regexp
(string-append "^[" letters digits "]"
"([" letters digits "-]*[" letters digits "])?$")))
(define top-label-regexp (define top-label-regexp
(make-regexp "^[a-zA-Z]([a-zA-Z0-9-]*[a-zA-Z0-9])?$")) (make-regexp
(string-append "^[" letters "]"
"([" letters digits "-]*[" letters digits "])?$")))
(define (valid-host? host) (define (valid-host? host)
(cond (cond
@ -203,13 +214,13 @@ for build-uri except there is no scheme."
(regexp-exec top-label-regexp host start))))))) (regexp-exec top-label-regexp host start)))))))
(define userinfo-pat (define userinfo-pat
"[a-zA-Z0-9_.!~*'();:&=+$,-]+") (string-append "[" letters digits "_.!~*'();:&=+$,-]+"))
(define host-pat (define host-pat
"[a-zA-Z0-9.-]+") (string-append "[" letters digits ".-]+"))
(define ipv6-host-pat (define ipv6-host-pat
"[0-9a-fA-F:.]+") (string-append "[" hex-digits ":.]+"))
(define port-pat (define port-pat
"[0-9]*") (string-append "[" digits "]*"))
(define authority-regexp (define authority-regexp
(make-regexp (make-regexp
(format #f "^//((~a)@)?((~a)|(\\[(~a)\\]))(:(~a))?$" (format #f "^//((~a)@)?((~a)|(\\[(~a)\\]))(:(~a))?$"
@ -246,7 +257,7 @@ for build-uri except there is no scheme."
;;; either. ;;; either.
(define scheme-pat (define scheme-pat
"[a-zA-Z][a-zA-Z0-9+.-]*") (string-append "[" letters "][" letters digits "+.-]*"))
(define authority-pat (define authority-pat
"[^/?#]*") "[^/?#]*")
(define path-pat (define path-pat

View file

@ -1,6 +1,6 @@
;;;; web-uri.test --- URI library -*- mode: scheme; coding: utf-8; -*- ;;;; web-uri.test --- URI library -*- mode: scheme; coding: utf-8; -*-
;;;; ;;;;
;;;; Copyright (C) 2010-2012, 2014, 2017 Free Software Foundation, Inc. ;;;; Copyright (C) 2010-2012, 2014, 2017, 2019 Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -121,7 +121,21 @@
(pass-if-uri-exception "http://foo@" (pass-if-uri-exception "http://foo@"
"Expected.*host" "Expected.*host"
(build-uri 'http #:userinfo "foo"))) (build-uri 'http #:userinfo "foo"))
;; In this test, we need to reload the '(web uri)' module with a
;; different locale. This is because some locale-dependent things
;; (e.g., compiled regexes) are computed when the module is loaded.
(pass-if-uri-exception "http://illégal.com"
"Expected.*host"
(dynamic-wind
(lambda () #t)
(lambda ()
(with-locale "en_US.utf8"
(reload-module (resolve-module '(web uri)))
(build-uri 'http #:host "illégal.com")))
(lambda ()
(reload-module (resolve-module '(web uri)))))))
(with-test-prefix "build-uri-reference" (with-test-prefix "build-uri-reference"
(pass-if "//host/etc/foo" (pass-if "//host/etc/foo"
@ -290,7 +304,20 @@
#:port 100 #:port 100
#:path "/" #:path "/"
#:query "q" #:query "q"
#:fragment "bar"))) #:fragment "bar"))
;; This test reproduces bug #35785. See the 'illégal' test above for
;; why we reload the module.
(pass-if "http://www.example.com (sv_SE)"
(dynamic-wind
(lambda () #t)
(lambda ()
(with-locale "sv_SE.utf8"
(reload-module (resolve-module '(web uri)))
(uri=? (string->uri "http://www.example.com")
#:scheme 'http #:host "www.example.com" #:path "")))
(lambda ()
(reload-module (resolve-module '(web uri)))))))
(with-test-prefix "string->uri-reference" (with-test-prefix "string->uri-reference"
(pass-if "/foo" (pass-if "/foo"