bug: add guard against string-paths in 'find-relative-path'

Add guard, if first argument to `find-relative-path` is not a path,
 then don't call `path-convention-type` on it.

Thanks to Jack Firth for reporting:
https://github.com/racket/rackunit/pull/46
This commit is contained in:
Ben Greenman 2017-06-28 10:19:50 -04:00 committed by GitHub
parent f9a39531e9
commit 04c1c15d89
2 changed files with 4 additions and 1 deletions

View File

@ -86,6 +86,7 @@
#:more-than-root? #t))
(test (bytes->path #"../.." 'unix) 'find-relative-path (find-relative-path (bytes->path #"/r/c" 'unix) (bytes->path #"/" 'unix)
#:more-than-root? #t))
(test "/" 'find-relative-path (find-relative-path "/" "/" #:more-than-root? #t))
(test (bytes->path #"..\\b\\a" 'windows) find-relative-path (bytes->path #"C:/r/c" 'windows) (bytes->path #"c:/R/b/a" 'windows))
(test (bytes->path #"..\\b\\a" 'windows) find-relative-path (bytes->path #"C:/r/c" 'windows) (bytes->path #"c:/r/b/a" 'windows))

View File

@ -134,7 +134,9 @@
p))])
(if (and (equal? (normalize (car dir)) (normalize (car file)))
(or (not more-than-root?)
(not (eq? 'unix (path-convention-type directory)))
(not (eq? 'unix (if (string? directory)
(system-path-convention-type)
(path-convention-type directory))))
(null? (cdr dir))
(null? (cdr file))
(equal? (normalize (cadr dir)) (normalize (cadr file)))))