diff --git a/collects/net/head-unit.ss b/collects/net/head-unit.ss index 48654bd1df..f9b7e3edf8 100644 --- a/collects/net/head-unit.ss +++ b/collects/net/head-unit.ss @@ -165,6 +165,7 @@ (define nonblank "[^ \t\n\r\v]") (define re:all-blank (regexp (format "^~a*$" blank))) (define re:quoted (regexp "\"[^\"]*\"")) + (define re:parened (regexp "[(][^)]*[)]")) (define re:comma (regexp ",")) (define re:comma-separated (regexp "([^,]*),(.*)")) @@ -177,8 +178,14 @@ null (let loop ([prefix ""][s s]) ;; Which comes first - a quote or a comma? - (let ([mq (regexp-match-positions re:quoted s)] - [mc (regexp-match-positions re:comma s)]) + (let* ([mq1 (regexp-match-positions re:quoted s)] + [mq2 (regexp-match-positions re:parened s)] + [mq (if (and mq1 mq2) + (if (< (caar mq1) (caar mq2)) + mq1 + mq2) + (or mq1 mq2))] + [mc (regexp-match-positions re:comma s)]) (if (and mq mc (< (caar mq) (caar mc) (cdar mq))) ;; Quote contains a comma (loop (string-append diff --git a/collects/tests/mzscheme/head.ss b/collects/tests/mzscheme/head.ss new file mode 100644 index 0000000000..1c53506dd8 --- /dev/null +++ b/collects/tests/mzscheme/head.ss @@ -0,0 +1,44 @@ + +(load-relative "loadtest.ss") + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; url.ss tests +;; + +(require (lib "head.ss" "net")) + +(for-each + (lambda (addr) + (test '("o.gu@plt-scheme.com") extract-addresses (car addr) 'address) + (test '("o.gu@plt-scheme.com" "o.gu@plt-scheme.com") extract-addresses + (format "~a, ~a" (car addr) (car addr)) + 'address) + (test (list (cdr addr)) extract-addresses (car addr) 'name) + (for-each + (lambda (addr2) + (let ([two (format " ~a, \n\t~a" (car addr) (car addr2))]) + (test '("o.gu@plt-scheme.com" "s.gu@plt-scheme.org") extract-addresses two 'address) + (test (list (cdr addr) (cdr addr2)) extract-addresses two 'name))) + '(("s.gu@plt-scheme.org" . "s.gu@plt-scheme.org") + ("" . "s.gu@plt-scheme.org") + ("s.gu@plt-scheme.org (Gu, Sophia)" . "Gu, Sophia") + ("s.gu@plt-scheme.org (Sophia Gu)" . "Sophia Gu") + ("s.gu@plt-scheme.org (Sophia \"Sophie\" Gu)" . "Sophia \"Sophie\" Gu") + ("Sophia Gu " . "Sophia Gu") + ("\"Gu, Sophia\" " . "\"Gu, Sophia\"") + ("\"Gu, Sophia (Sophie)\" " . "\"Gu, Sophia (Sophie)\"")))) + '(("o.gu@plt-scheme.com" . "o.gu@plt-scheme.com") + ("" . "o.gu@plt-scheme.com") + ("o.gu@plt-scheme.com (Gu, Oliver)" . "Gu, Oliver") + ("o.gu@plt-scheme.com (Oliver Gu)" . "Oliver Gu") + ("o.gu@plt-scheme.com (Oliver \"Ollie\" Gu)" . "Oliver \"Ollie\" Gu") + ("o.gu@plt-scheme.com (Oliver \"Ollie Gu)" . "Oliver \"Ollie Gu") + ("Oliver Gu " . "Oliver Gu") + ("\"Gu, Oliver\" " . "\"Gu, Oliver\"") + ("\"Gu, Oliver (Ollie)\" " . "\"Gu, Oliver (Ollie)\"") + ("\"Gu, Oliver (Ollie\" " . "\"Gu, Oliver (Ollie\"") + ("\"Gu, Oliver (Ollie, himself)\" " . "\"Gu, Oliver (Ollie, himself)\""))) + + +(report-errs)