Reviewers: Sven,
Message:
PTAL.
The bug: readline() did not continue reading from a line that exceeded the
buffer length of 256.
Description:
Fixed: regression in issue 1579 concerning readline() in d8.
BUG=v8:1579
Please review this at http://codereview.chromium.org/7537023/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/d8.cc
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index
ac203746523a8ee83015a4968b0ad3cda7e9a6f0..61442d42d9958d6f165e435aa721674f8f4ffb52
100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -226,17 +226,23 @@ Handle<Value> Shell::ReadLine(const Arguments& args) {
static const int kBufferSize = 256;
char buffer[kBufferSize];
Handle<String> accumulator = String::New("");
- bool linebreak;
int length;
- do { // Repeat if the line ends with an escape '\'.
- // fgets got an error. Just give up.
+ while (true) {
+ // Continue reading if the line ends with an escape '\\' or the line
has
+ // not been fully read into the buffer yet (does not end with '\n').
+ // If fgets gets an error. Just give up.
if (fgets(buffer, kBufferSize, stdin) == NULL) return Null();
length = static_cast<int>(strlen(buffer));
- linebreak = (length > 1 && buffer[length-2] == '\\');
- if (linebreak) buffer[length-2] = '\n';
- accumulator = String::Concat(accumulator, String::New(buffer,
length-1));
- } while (linebreak);
- return accumulator;
+ if (length == 0) return accumulator;
+ if (buffer[length-1] == '\n') {
+ length--;
+ if (length == 0 || buffer[length-1] != '\\') {
+ return String::Concat(accumulator, String::New(buffer, length));
+ }
+ buffer[length-1] = '\n';
+ }
+ accumulator = String::Concat(accumulator, String::New(buffer, length));
+ }
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev