Issue #13886: Fix input() to not strip out supposedly-invalid input bytes.
Also fix sporadic failures in test_builtin due to dependence on whether the
readline module has previously been imported.
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index dab56ce..a3c8dcc 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -18,6 +18,13 @@
import pty, signal
except ImportError:
pty = signal = None
+# Importing this module has the side-effect of changing the behavior of input().
+# Ensure that we always use the readline version (if available), so we don't get
+# different results depending on what other tests have already imported.
+try:
+ import readline
+except ImportError:
+ pass
class Squares:
diff --git a/Misc/NEWS b/Misc/NEWS
index c216cc9..3543feb 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@
Core and Builtins
-----------------
+- Issue #13886: Fix input() to not strip out input bytes that cannot be decoded
+ using the locale encoding. Also fix sporadic failures in test_builtin due to
+ dependence on whether the readline module has previously been imported.
+
- Issue #10156: In the interpreter's initialization phase, unicode globals
are now initialized dynamically as needed.
diff --git a/Modules/readline.c b/Modules/readline.c
index 4d54dad..fd60377 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -1068,7 +1068,7 @@
char *saved_locale = strdup(setlocale(LC_CTYPE, NULL));
if (!saved_locale)
Py_FatalError("not enough memory to save locale");
- setlocale(LC_CTYPE, "");
+ setlocale(LC_CTYPE, "C");
#endif
if (sys_stdin != rl_instream || sys_stdout != rl_outstream) {