diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-02-23 12:07:37 +0000 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-02-23 12:07:37 +0000 |
commit | c0f1a1afae3843986eb0bef54b165424361f2510 (patch) | |
tree | c650a798108af5024bcee2c01ae8f67586c952c8 /Python/bltinmodule.c | |
parent | Issue #11224: Improved sparse file read support (r85916) introduced a (diff) | |
download | cpython-c0f1a1afae3843986eb0bef54b165424361f2510.tar.gz cpython-c0f1a1afae3843986eb0bef54b165424361f2510.tar.bz2 cpython-c0f1a1afae3843986eb0bef54b165424361f2510.zip |
Issue #11272: Fix input() and sys.stdin for Windows newline
On Windows, input() strips '\r' (and not only '\n'), and sys.stdin uses
universal newline (replace '\r\n' by '\n').
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r-- | Python/bltinmodule.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 42bc8091e16..c6bb16c4e11 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1618,6 +1618,7 @@ builtin_input(PyObject *self, PyObject *args) PyObject *stdin_encoding; char *stdin_encoding_str; PyObject *result; + size_t len; stdin_encoding = PyObject_GetAttrString(fin, "encoding"); if (!stdin_encoding) @@ -1682,19 +1683,23 @@ builtin_input(PyObject *self, PyObject *args) Py_DECREF(stdin_encoding); return NULL; } - if (*s == '\0') { + + len = strlen(s); + if (len == 0) { PyErr_SetNone(PyExc_EOFError); result = NULL; } - else { /* strip trailing '\n' */ - size_t len = strlen(s); + else { if (len > PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "input: input too long"); result = NULL; } else { - result = PyUnicode_Decode(s, len-1, stdin_encoding_str, NULL); + len--; /* strip trailing '\n' */ + if (len != 0 && s[len-1] == '\r') + len--; /* strip trailing '\r' */ + result = PyUnicode_Decode(s, len, stdin_encoding_str, NULL); } } Py_DECREF(stdin_encoding); |