summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_unicode.py6
-rw-r--r--Objects/unicodeobject.c2
2 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 870853e..14d3fa6 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -275,6 +275,12 @@ class UnicodeTest(string_tests.CommonTest,
self.checkequalnofix('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1)
self.assertRaises(TypeError, 'replace'.replace, "r", 42)
+ @support.cpython_only
+ def test_replace_id(self):
+ a = 'a' # single ascii letters are singletons
+ text = 'abc'
+ self.assertIs(text.replace('a', 'a'), text)
+
def test_bytes_comparison(self):
with support.check_warnings():
warnings.simplefilter('ignore', BytesWarning)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index caad326..8608776 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9604,6 +9604,8 @@ replace(PyObject *self, PyObject *str1,
else if (maxcount == 0 || slen == 0)
goto nothing;
+ if (str1 == str2)
+ goto nothing;
if (skind < kind1)
/* substring too wide to be present */
goto nothing;