From afcecc73f1f1f24112021596db287ffb4e5de43e Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 3 Nov 2013 09:57:26 -0700 Subject: [PATCH] {string,bytes}->path-element: error on empty [byte] string --- .../racket-test/tests/racket/path.rktl | 3 +++ racket/collects/racket/HISTORY.txt | 2 ++ racket/src/racket/src/file.c | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pkgs/racket-pkgs/racket-test/tests/racket/path.rktl b/pkgs/racket-pkgs/racket-test/tests/racket/path.rktl index 4165782fbe..1c92d800a6 100644 --- a/pkgs/racket-pkgs/racket-test/tests/racket/path.rktl +++ b/pkgs/racket-pkgs/racket-test/tests/racket/path.rktl @@ -897,6 +897,9 @@ (err/rt-test (bytes->path-element "a/b" 'unix)) (err/rt-test (bytes->path-element "a\\b" 'windows)) +(err/rt-test (bytes->path-element #"")) +(err/rt-test (string->path-element "")) + (test #"\\\\?\\REL\\\\a/b" path->bytes (bytes->path-element #"a/b" 'windows)) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/racket/collects/racket/HISTORY.txt b/racket/collects/racket/HISTORY.txt index 63992dfd20..6bf4c31cfd 100644 --- a/racket/collects/racket/HISTORY.txt +++ b/racket/collects/racket/HISTORY.txt @@ -1,5 +1,7 @@ Version 5.90.0.10 Added chaperone-channel and impersonate-channel +Change string->path-element and bytes->path-element to raise an + exception for an empty [byte-]string argument Version 5.90.0.9 Allow hash table chaperones and impersonators to support efficient diff --git a/racket/src/racket/src/file.c b/racket/src/racket/src/file.c index e8209da0c7..656e6aa2db 100644 --- a/racket/src/racket/src/file.c +++ b/racket/src/racket/src/file.c @@ -1036,19 +1036,24 @@ static Scheme_Object *do_bytes_to_path_element(const char *name, Scheme_Object * } } - if (i >= len) - p = make_protected_sized_offset_path(1, SCHEME_BYTE_STR_VAL(s), - 0, len, - SCHEME_MUTABLEP(s), 0, - kind); - else + if (i >= len) { + if (len == 0) + p = NULL; + else + p = make_protected_sized_offset_path(1, SCHEME_BYTE_STR_VAL(s), + 0, len, + SCHEME_MUTABLEP(s), 0, + kind); + } else p = NULL; if (!p || !is_path_element(p)) scheme_contract_error(name, "cannot be converted to a path element", "path", 1, argv[0], - "explanation", 0, "path can be split, is not relative, or names a special element", + "explanation", 0, (len + ? "path can be split, is not relative, or names a special element" + : "path element cannot be empty"), NULL); return p;