Skip to content

Commit b6f7ba2

Browse files
committed
fix: -p/-P flag consistency (CRITICAL) + JS module type
CRITICAL: Lua had -p = --preserve <chars> (needs arg) and no -P, while C/Zig/FFI/Node use -p = --passthrough (no arg) and -P = --preserve. Same command line did opposite things or errored depending on the binary. Lua now matches the 4-impl majority: -p = passthrough, -P = preserve. Also accept the --preserve=chars attached form (the other four already do). JS: add package.json with "type": "module" so Node 24 stops emitting the MODULE_TYPELESS_PACKAGE_JSON warning to stderr (which broke the stderr-purity test). All four impls now pass test/test including new cross-impl test #5d (-p passthrough / -P preserve).
1 parent b058c76 commit b6f7ba2

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

bin/printable-binary

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ if arg then
522522
io.stderr:write("Usage: " .. progname .. " [options] [file]\n")
523523
io.stderr:write("Options:\n")
524524
io.stderr:write(" -d, --decode Decode mode (default is encode mode)\n")
525-
io.stderr:write(" --passthrough Pass input to stdout unchanged, send encoded data to stderr\n")
525+
io.stderr:write(" -p, --passthrough Pass input to stdout unchanged, send encoded data to stderr\n")
526526
io.stderr:write("\n")
527527
io.stderr:write("Encoding modes:\n")
528528
io.stderr:write(" -X, --hexlike Hexlike mode: passthrough ASCII stays as-is, all other bytes\n")
@@ -535,7 +535,7 @@ if arg then
535535
io.stderr:write(" -t, --tabs, --preserve-tabs Preserve literal tabs\n")
536536
io.stderr:write(" -n, --crlf, --preserve-newlines Preserve literal CR/LF\n")
537537
io.stderr:write(" -w, --preserve-whitespace Preserve all whitespace (spaces, tabs, CR/LF)\n")
538-
io.stderr:write(" -p, --preserve <chars> Preserve specific characters (e.g., -p '!\"')\n")
538+
io.stderr:write(" -P, --preserve <chars> Preserve specific characters (e.g., -P '!\"')\n")
539539
io.stderr:write(" --no-double-encode-check Skip detection of already-encoded input\n")
540540
io.stderr:write("\n")
541541
io.stderr:write("Range options (select byte range from input before processing):\n")
@@ -726,9 +726,11 @@ if arg then
726726
elseif flag == "S" then
727727
strip_whitespace = true
728728
elseif flag == "p" then
729+
passthrough_mode = true
730+
elseif flag == "P" then
729731
local next_arg = get_next_arg()
730732
if not next_arg then
731-
io.stderr:write("Error: -p requires an argument\n")
733+
io.stderr:write("Error: -P requires an argument\n")
732734
os.exit(1)
733735
end
734736
preserve_chars = next_arg
@@ -803,6 +805,8 @@ if arg then
803805
io.stderr:write("Error: --end value must be a number\n")
804806
os.exit(1)
805807
end
808+
elseif current_arg:match("^%-%-preserve=") then
809+
preserve_chars = current_arg:match("^%-%-preserve=(.*)")
806810
elseif current_arg == "--preserve" then
807811
i = i + 1
808812
if not arg[i] then

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "printable-binary",
3+
"version": "1.0.0",
4+
"description": "Encode arbitrary binary data into human-readable UTF-8 and back (Node/ESM implementation).",
5+
"type": "module",
6+
"private": true,
7+
"bin": {
8+
"printable-binary-node": "bin/printable-binary-node.js"
9+
},
10+
"main": "js/printable_binary.js",
11+
"license": "MIT"
12+
}

test/test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@ else
253253
echo -e "${YELLOW}SKIP (no character_map.txt in cwd)${NC}"
254254
fi
255255
256+
# Test 5d: -p (passthrough) / -P (preserve) short-flag consistency across all impls
257+
echo -e "${BLUE}Test #5d: -p passthrough / -P preserve consistency${NC}"
258+
PT=$(printf 'hi' | $SCRIPT -p 2>/dev/null)
259+
PR=$(printf '!' | $SCRIPT -P '!' 2>/dev/null)
260+
if [[ "$PT" == "hi" && "$PR" == "!" ]]; then
261+
echo -e "${GREEN}PASS${NC}"
262+
else
263+
echo -e "${RED}FAIL${NC} (-p passthrough='$PT' want 'hi'; -P preserve='$PR' want '!')"
264+
exit 1
265+
fi
266+
256267
# Test 6: Piped input
257268
echo -e "${BLUE}Test #6: Piped input${NC}"
258269
RESULT=$(echo -n "Test" | $SCRIPT | $SCRIPT -d)

0 commit comments

Comments
 (0)