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`.
This commit is contained in:
parent
685859b408
commit
26cb1f7ce6
|
@ -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")
|
||||
|
|
|
@ -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)))))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user