diff --git a/pkgs/racket-test/tests/setup/bad%coll/m.rkt b/pkgs/racket-test/tests/setup/bad%coll/m.rkt new file mode 100644 index 0000000000..4b553d8438 --- /dev/null +++ b/pkgs/racket-test/tests/setup/bad%coll/m.rkt @@ -0,0 +1,2 @@ +#lang racket +"The enclosing directory is not a valid collection-path name" diff --git a/pkgs/racket-test/tests/setup/path-to-collects.rkt b/pkgs/racket-test/tests/setup/path-to-collects.rkt new file mode 100644 index 0000000000..32af26df9c --- /dev/null +++ b/pkgs/racket-test/tests/setup/path-to-collects.rkt @@ -0,0 +1,26 @@ +#lang racket/base +(require setup/collects + rackunit + setup/dirs + racket/path) + +(check-equal? '(lib "racket/base.rkt") + (path->module-path (build-path (find-collects-dir) "racket" "base.rkt"))) +(check-equal? '(collects #"racket" #"base.rkt") + (path->collects-relative (build-path (find-collects-dir) "racket" "base.rkt"))) + +(check-equal? '(lib "planet/private/nonesuch.rkt") + (path->module-path (build-path (find-collects-dir) "planet" "private" "nonesuch.rkt"))) +(check-equal? '(collects #"planet" #"private" #"nonesuch.rkt") + (path->collects-relative (build-path (find-collects-dir) "planet" "private" "nonesuch.rkt"))) + +(check-equal? (build-path (find-collects-dir) "planet" "private" "none!such.rkt") + (path->module-path (build-path (find-collects-dir) "planet" "private" "none!such.rkt"))) +(check-equal? '(collects #"planet" #"private" #"none!such.rkt") + (path->collects-relative (build-path (find-collects-dir) "planet" "private" "none!such.rkt"))) + +(define here (collection-file-path "path-to-collects.rkt" "tests/setup")) +(check-equal? (build-path here "bad%coll" "m.rkt") + (path->module-path (build-path here "bad%coll" "m.rkt"))) +(check-equal? (build-path here "bad%coll" "m.rkt") + (path->collects-relative (build-path here "bad%coll" "m.rkt"))) diff --git a/racket/collects/setup/collects.rkt b/racket/collects/setup/collects.rkt index 56b9e38280..7fc57da973 100644 --- a/racket/collects/setup/collects.rkt +++ b/racket/collects/setup/collects.rkt @@ -1,6 +1,7 @@ #lang racket/base (require racket/list racket/string + setup/collection-name pkg/path) (provide path->module-path @@ -28,6 +29,9 @@ (cons pkg-collect l) l))) (define c-p (and (pair? new-c-l) + (or (not (eq? mode 'module-path)) + (module-path? (car p-l))) + (andmap collection-name-element? new-c-l) (apply collection-file-path (car p-l) new-c-l #:fail (lambda (msg) #f)))) (and c-p @@ -36,7 +40,8 @@ [else #f])) (define p-l (reverse (explode-path simple-p))) (or (and ((length p-l) . > . 2) - (regexp-match? #rx#"^[-a-zA-Z0-9_+%.]*$" (path-element->bytes (car p-l))) + (or (not (eq? mode 'module-path)) + (module-path? (path-element->string (car p-l)))) ;; Try using path suffixes as library names, checking whether ;; `collection-file-path' locates the same path. (let ([file (path-element->string (car p-l))]) @@ -44,7 +49,7 @@ (cond [(null? p-l) #f] [(null? (cdr p-l)) #f] - [(regexp-match? #rx#"^[-a-zA-Z0-9_+%]*$" (path-element->bytes (car p-l))) + [(collection-name-element? (path-element->string (car p-l))) (define new-c-l (cons (path-element->string (car p-l)) c-l)) (define c-p (apply collection-file-path file new-c-l #:fail (lambda (msg) #f))) (if (and c-p