From dcf52dbba5e2fcbcc9910e306acf298e1a019c3e Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Wed, 5 Oct 2022 17:15:56 +0200 Subject: [PATCH] fix path --null-out Regression from 7bc4c9674bb24f09e0b7af89442f700864217327. Appending `"\0"` to an std::string does nothing. I blame C++. --- src/builtins/path.cpp | 4 +++- tests/checks/path.fish | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/builtins/path.cpp b/src/builtins/path.cpp index 2c19a2bc6..07d8cb92e 100644 --- a/src/builtins/path.cpp +++ b/src/builtins/path.cpp @@ -201,7 +201,9 @@ static void path_out(io_streams_t &streams, const options_t &opts, const wcstrin if (!opts.null_out) { streams.out.append_with_separation(str, separation_type_t::explicitly); } else { - streams.out.append(str + L"\0"); + // Note the char - if this was a string instead we'd add + // a string of length 0, i.e. nothing + streams.out.append(str + L'\0'); } } } diff --git a/tests/checks/path.fish b/tests/checks/path.fish index 8f5d526f3..1e3b0377e 100644 --- a/tests/checks/path.fish +++ b/tests/checks/path.fish @@ -222,3 +222,11 @@ set -l epochtime (path mtime epoch) # Allow for timezone shenanigans test $epochtime -gt 0 -a $epochtime -lt 180000 or echo Oops not mtime + +path basename -Z foo bar baz | path sort +# CHECK: bar +# CHECK: baz +# CHECK: foo + +path basename --null-out bar baz | string escape +# CHECK: bar\x00baz\x00