Commit Graph

10 Commits

Author SHA1 Message Date
Kurtis Rader
5dc78dd858 fix regression involving read from scripts
Fixes #4206
2017-07-15 21:21:24 -07:00
Kurtis Rader
d383e3b92c define the var when the read limit is exceeded
This problem was found when testing the change for issue #4163 to make
dereferencing an undefined variable an error.

Fixes #4180
2017-07-03 16:14:28 -07:00
Kurtis Rader
af7f5f42b6 put upper bound on data read will consume
This puts a hard upper bound of 10 MiB on the amount of data that read
will consume. This is to avoid having the shell consume an unreasonable
amount of memory, possibly causing the system to enter a OOM condition,
if the user does something non-sensical.

Fixes #3712
2017-02-09 21:04:46 -08:00
ridiculousfish
812e977e62 Clean up /tmp/fish_chunked_read_test.txt after tests 2017-01-21 12:47:05 -08:00
ridiculousfish
5a5a6a6968 Correctly handle multiple chunks from read_in_chunks
read_in_chunks does not clear the intermediate string 'str'
between iterations, so every chunk has every other chunk prepended
to it.

A secondary issue is that it calls str2wcstring() on an intermediate
chunk, which may split multi-byte sequences. This needs to be deferred
to the end.

Test added. Fixes #3756
2017-01-21 12:43:20 -08:00
Kevin Ballard
a012aedb31 Fix incorrect error on read with 1-character input
When `read` is given a single character of input (including the
newline), it was bailing as if it had been given no input. This is
incorrect.
2014-09-21 20:00:26 -07:00
Kevin Ballard
8f8c4cdd17 Implement new read --null flag
The `--null` flag to `read` makes it split incoming lines on NUL instead
of newlines. This is intended for processing the output of a command
that uses NUL separators (such as `find -print0`).

Fixes #1694.
2014-09-21 19:27:26 -07:00
Joseph Tannhuber
4acea72700 New -n option for read builtin
Usage: read -n nchars
Reads maximum of nchars characters. If nchars <= 0, there's no limit.
2014-09-03 22:48:37 -07:00
Kevin Ballard
7fce9e2411 Trim trailing newline on cmdsubst when IFS=''
When $IFS is empty, command substitution no longer splits on newlines.
However we still want to trim off a single trailing newline, as most
commands will emit a trailing newline and it makes it harder to work
with their output.
2014-08-29 12:48:45 -07:00
Kevin Ballard
973dd6ffbd read: Support arrays, character splitting
Enhance the `read` builtin to support creating an array with the --array
flag. With --array, only a single variable name is allowed and the
entire input is tokenized and placed into that variable as an array.

Also add custom behavior if IFS is empty or unset. In that event, split
the input on every character, instead of the previous behavior of doing
no splitting at all.
2014-07-14 00:46:38 -07:00