hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3f95b1ac8286e816bfaf0a1fed6a16b54f36ed72
parent 651a2e46a922f6e097784c8cceaa4201dbc43501
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Mar 2021 15:20:29 -0500

path::join: handle empty string

Diffstat:
Mpath/join.ha | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/path/join.ha b/path/join.ha @@ -14,9 +14,10 @@ export fn join(paths: path...) path = { let buf = pathbytes(paths[i]); let l = len(buf); - for (buf[l - 1] == PATHSEP) { + for (l > 0 && buf[l - 1] == PATHSEP) { l -= 1; }; + if (l == 0) continue; for (let q = 0z; q < l) { let w = io::write(sink, buf[q..l]) as size; q += w; @@ -56,4 +57,8 @@ export fn join(paths: path...) path = { let p = join("foo///", "bar"); defer path_free(p); assert(p as str == "foo/bar"); + + let p = join("foo", "", "bar"); + defer path_free(p); + assert(p as str == "foo/bar"); };