[Jython-checkins] jython: Raise a ValueError when unichr() is called with a value that maps to a
alex.gronholm
jython-checkins at python.org
Sat Aug 16 01:08:53 CEST 2014
http://hg.python.org/jython/rev/83cd10f1826d
changeset: 7359:83cd10f1826d
user: Alex Grönholm <alex.gronholm at nextday.fi>
date: Sat Aug 16 01:53:53 2014 +0300
summary:
Raise a ValueError when unichr() is called with a value that maps to a surrogate character. A better fix for issue #2190.
files:
Lib/test/test_unicode_jy.py | 5 +++--
src/org/python/core/__builtin__.java | 3 +++
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_unicode_jy.py b/Lib/test/test_unicode_jy.py
--- a/Lib/test/test_unicode_jy.py
+++ b/Lib/test/test_unicode_jy.py
@@ -105,9 +105,10 @@
def test_repr(self):
self.assert_(isinstance('%r' % u'foo', str))
- def test_unicode_repr(self):
+ def test_unicode_lone_surrogate(self):
# http://bugs.jython.org/issue2190
- self.assertEqual(repr(unichr(0xd800)), r"u'\ud800'")
+ self.assertRaises(ValueError, unichr, 0xd800)
+ self.assertRaises(ValueError, unichr, 0xdfff)
def test_concat(self):
self.assertRaises(UnicodeDecodeError, lambda : u'' + '毛泽东')
diff --git a/src/org/python/core/__builtin__.java b/src/org/python/core/__builtin__.java
--- a/src/org/python/core/__builtin__.java
+++ b/src/org/python/core/__builtin__.java
@@ -405,6 +405,9 @@
if (i < 0 || i > PySystemState.maxunicode) {
throw Py.ValueError("unichr() arg not in range(0x110000)");
}
+ if (i >= 0xD800 && i <= 0xDFFF) {
+ throw Py.ValueError("unichr() arg is a lone surrogate in range (0xD800, 0xDFFF) (Jython UTF-16 encoding)");
+ }
return i;
}
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list