Skip to content

Commit e465f7d

Browse files
committed
Fix a bug with --raw flag about reading all lines if no newline is present at the end of the file
1 parent 6793ff4 commit e465f7d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

npm/index.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/test.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ async function test(name, fn) {
1010

1111
async function run(json, code = '') {
1212
const {spawnSync} = await import('node:child_process')
13-
return spawnSync(`echo '${typeof json === 'string' ? json : JSON.stringify(json)}' | node index.js ${code}`, {
13+
return spawnSync(`printf -- '${typeof json === 'string' ? json : JSON.stringify(json)}' | node index.js ${code}`, {
1414
stdio: 'pipe',
1515
encoding: 'utf8',
1616
shell: true
1717
})
1818
}
1919

20-
async function runSimple(code = '') {
20+
async function runNoPipe(code = '') {
2121
const {spawnSync} = await import('node:child_process')
2222
return spawnSync(`node index.js ${code}`, {
2323
stdio: 'pipe',
@@ -197,6 +197,11 @@ void async function main() {
197197
t.equal(stdout, 'string\n')
198198
})
199199

200+
await test('flags - raw reads entire input', async t => {
201+
const {stdout} = await run('foo\bbar', `-r`)
202+
t.equal(stdout, 'foo\bbar\n')
203+
})
204+
200205
await test('flags - slurp flag', async t => {
201206
const {stdout} = await run('{"foo": "bar"}\n{"foo": "baz"}', `-s '.[1].foo'`)
202207
t.equal(stdout, 'baz\n')
@@ -208,12 +213,12 @@ void async function main() {
208213
})
209214

210215
await test('cli - first arg is file', async t => {
211-
const {stdout} = await runSimple(`package.json .name`)
216+
const {stdout} = await runNoPipe(`package.json .name`)
212217
t.equal(stdout, 'fx\n')
213218
})
214219

215220
await test('cli - last arg is file', async t => {
216-
const {stdout} = await runSimple(`.name package.json`)
221+
const {stdout} = await runNoPipe(`.name package.json`)
217222
t.equal(stdout, 'fx\n')
218223
})
219224
}()

0 commit comments

Comments
 (0)