dor send --stdin interprets backslash escapes in piped bytes
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 50/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- cli
Research direction
Start in dor/src/commands/send.ts at the stdin handling and text escape conversion described in the issue. Confirm the current behavior with the documented piping example, then wait for the maintainer to choose between raw stdin by default and documenting the existing behavior. Done means the chosen contract is implemented or documented, with a regression test preserving the relevant bytes.
Written by the indexing model from the issue text.
Description
dor send --stdin interprets backslash escapes in piped bytes, corrupting the documented use case
dor send --stdin reads standard input and forwards it as a text input:
if (flags.stdin === true) {
if (!readStdin) return { ok: false, message: 'stdin is not available' };
return { ok: true, value: [{ kind: 'text', text: await readStdin() }] };
}
Text inputs then run through interpretTextEscapes unless --raw is set:
input += raw ? item.text : interpretTextEscapes(item.text);
(send.ts:227-228, converting \n \r \t \\ at send.ts:238-253)
Why this is a footgun for --stdin
The flagship stdin example in the help is:
cat script.sh | dor send surface:3 --stdin
Bytes arriving on stdin are already literal — they are not a shell-authored string where a two-character \t stands in for a tab. Shell scripts routinely contain literal backslash sequences (printf 'a\tb', sed 's/\n/ /', grep -P '\d', Windows paths with \\). Piping such a file through --stdin silently rewrites every \n/\r/\t/\\, so the text typed into the target terminal is not the file's contents.
Repro: printf 'printf "a\\tb\\n"\n' | dor send surface:3 --stdin types a real TAB and newline into the middle of the line instead of the literal \t/\n the script source contains.
The escape interpretation is desirable for --text "echo hi\nthere" (a human types escapes on the command line), but for --stdin the input is already-real bytes.
Design question (why an issue, not a drive-by PR)
The current behavior is consistent with the documented contract — the help says "Text input interprets backslash escapes … unless --raw is set" (send.ts:97), and --stdin is documented as text input — so flipping the default is a contract change that needs a maintainer call. Options:
- Make
--stdinraw by default — treat piped bytes as literal; keep--textinterpreting escapes. Most aligned with thecat script.sh | …example. Would need an opt-in flag if anyone wants escape interpretation on stdin. - Keep current behavior, document it — call out at the
--stdinhelp that it interprets escapes and that--rawis needed for literal file contents.
I lean toward option 1, but it changes documented behavior, so I'm leaving the call to a maintainer. Happy to open the PR (including a regression test that pipes a script containing \t and asserts the bytes are preserved) once a direction is chosen.
Surfaced by the nightly code-quality survey.
- Dominant language
- TypeScript
- Stars
- 5
- Forks
- 1
- Avg merge
- 17h 45m
- Merged PRs (30d)
- 235
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from diffplug/dormouse
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
security-audit-failure
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
All issues in diffplug/dormouse
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vicharanashala/fln#563 ·