Skip to content

Commit

Permalink
Remove false-positive in incorrect stdin(4) detection
Browse files Browse the repository at this point in the history
Previously, when the file-descriptor `0` (stdin) was a FIFO, and
the process reported not being in a TTY, and files were given, an
incorrect error was thrown.

Now, when files are given, stdin(4) is completely and silently ignored,
when no files are given and the process reports being a TTY, an error
is thrown, and when no files are given and the process reports not
being a TTY, stdin(4) is read.

Closes GH-176.
Closes remarkjs/gulp-remark#9.
  • Loading branch information
wooorm committed Apr 22, 2016
1 parent 9e18c08 commit e1aa9f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
13 changes: 2 additions & 11 deletions lib/cli/file-set-pipeline/stdin.js
Expand Up @@ -16,7 +16,6 @@
*/

var debug = require('debug')('remark:cli:file-set-pipeline:stdin');
var fs = require('fs');
var toVFile = require('to-vfile');
var concat = require('concat-stream');

Expand All @@ -25,12 +24,6 @@ var concat = require('concat-stream');
*/

var isTTY = process.stdin.isTTY;
var isFIFO;

try { isFIFO = fs.fstatSync(0).isFIFO(); } catch (e) { /* Empty */ }

var definitelyTTY = isTTY === true || isFIFO === true;
var expextPipeIn = !isTTY;

/**
* Read from standard in.
Expand All @@ -46,9 +39,7 @@ function stdin(context, done) {
if (context.files.length) {
debug('Ignoring stdin');

if (definitelyTTY && expextPipeIn) {
err = new Error('remark does not accept both files and stdin');
} else if (context.filePath) {
if (context.filePath) {
err = new Error(
'remark does not accept `--file-path` for real files.\n' +
'Did you mean to pass stdin?'
Expand All @@ -60,7 +51,7 @@ function stdin(context, done) {
return;
}

if (definitelyTTY && !expextPipeIn) {
if (isTTY) {
done(new Error('No input'));

return;
Expand Down
4 changes: 0 additions & 4 deletions test/cli.sh
Expand Up @@ -95,10 +95,6 @@ it "Should not fail on multiple files"
$COMMAND "$markdown" "$markdown" > /dev/null 2>&1
assert $? 0

it "Should fail on stdin and files"
cat "$markdown" | $COMMAND "$markdown" > /dev/null 2>&1
assert $? 1

it "Should ignore herestring when with files (for now)"
$COMMAND $markdown <<< "$(cat $markdown)" > /dev/null 2>&1
assert $? 0
Expand Down

0 comments on commit e1aa9f6

Please sign in to comment.