From 26cb1f7ce632d7efb42abef86bfc57324fa16319 Mon Sep 17 00:00:00 2001 From: Scott Moore Date: Fri, 20 Dec 2013 14:45:36 -0800 Subject: [PATCH] path-element? should disallow '.' and '..' Fix `path-element?` to check whether the name returned by split-path is a path or a special entry. This behavior matches both the documentation of `path-element?` and the implementation of `string->path-element`. --- .../racket-test/tests/racket/pathlib.rktl | 20 ++++++++++++++++++- racket/collects/racket/path.rkt | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkgs/racket-pkgs/racket-test/tests/racket/pathlib.rktl b/pkgs/racket-pkgs/racket-test/tests/racket/pathlib.rktl index 423b034451..685b172b5d 100644 --- a/pkgs/racket-pkgs/racket-test/tests/racket/pathlib.rktl +++ b/pkgs/racket-pkgs/racket-test/tests/racket/pathlib.rktl @@ -3,13 +3,31 @@ (Section 'path) -(require scheme/path) +(require racket/path) (define (rtest f args result) (test result f args)) ;; ---------------------------------------- +(test #t path-element? (build-path "filename")) +(test #t path-element? (bytes->path #"filename" 'unix)) +(test #t path-element? (bytes->path #"filename" 'windows)) +(test #f path-element? (build-path "file" "next")) +(test #f path-element? (build-path (bytes->path #"file" 'unix) + (bytes->path #"next" 'unix))) +(test #f path-element? (build-path (bytes->path #"file" 'windows) + (bytes->path #"next" 'windows))) +(test #f path-element? (build-path 'up)) +(test #f path-element? (build-path 'same)) +(test #f path-element? (build-path/convention-type 'unix 'up)) +(test #f path-element? (build-path/convention-type 'unix 'same)) +(test #f path-element? (build-path/convention-type 'windows 'up)) +(test #f path-element? (build-path/convention-type 'windows 'same)) +(test #f ormap path-element? (filesystem-root-list)) + +;; ---------------------------------------- + (rtest explode-path "a/b" (list (string->path "a") (string->path "b"))) (rtest explode-path "a/../b" (list (string->path "a") diff --git a/racket/collects/racket/path.rkt b/racket/collects/racket/path.rkt index d08496ed41..3210cc69d5 100644 --- a/racket/collects/racket/path.rkt +++ b/racket/collects/racket/path.rkt @@ -184,7 +184,8 @@ (define (path-element? path) (and (path-for-some-system? path) (let-values ([(base name d?) (split-path path)]) - (eq? base 'relative)))) + (and (eq? base 'relative) + (path-for-some-system? name)))))