Skip to content

[2.7] bpo-29456: Fix bugs in unicodedata.normalize: u1176, u11a7 and u11c3 (GH-1958) #7704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_unicodedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ def test_issue10254(self):
b = u'C\u0338' * 20 + u'\xC7'
self.assertEqual(self.db.normalize('NFC', a), b)

def test_issue29456(self):
# Fix #29456
u1176_str_a = u'\u1100\u1176\u11a8'
u1176_str_b = u'\u1100\u1176\u11a8'
u11a7_str_a = u'\u1100\u1175\u11a7'
u11a7_str_b = u'\uae30\u11a7'
u11c3_str_a = u'\u1100\u1175\u11c3'
u11c3_str_b = u'\uae30\u11c3'
self.assertEqual(self.db.normalize('NFC', u1176_str_a), u1176_str_b)
self.assertEqual(self.db.normalize('NFC', u11a7_str_a), u11a7_str_b)
self.assertEqual(self.db.normalize('NFC', u11c3_str_a), u11c3_str_b)


def test_east_asian_width(self):
eaw = self.db.east_asian_width
self.assertRaises(TypeError, eaw, 'a')
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,7 @@ Jason Yeo
EungJun Yi
Bob Yodlowski
Danny Yoo
Wonsup Yoon
Rory Yorke
George Yoshida
Kazuhiro Yoshida
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bugs in hangul normalization: u1176, u11a7 and u11c3
8 changes: 6 additions & 2 deletions Modules/unicodedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,18 @@ nfc_nfkc(PyObject *self, PyObject *input, int k)
pairs, since we always have decomposed data. */
if (LBase <= *i && *i < (LBase+LCount) &&
i + 1 < end &&
VBase <= i[1] && i[1] <= (VBase+VCount)) {
VBase <= i[1] && i[1] < (VBase+VCount)) {
/* check L character is a modern leading consonant (0x1100 ~ 0x1112)
and V character is a modern vowel (0x1161 ~ 0x1175). */
int LIndex, VIndex;
LIndex = i[0] - LBase;
VIndex = i[1] - VBase;
code = SBase + (LIndex*VCount+VIndex)*TCount;
i+=2;
if (i < end &&
TBase <= *i && *i <= (TBase+TCount)) {
TBase < *i && *i < (TBase+TCount)) {
/* check T character is a modern trailing consonant
(0x11A8 ~ 0x11C2). */
code += *i-TBase;
i++;
}
Expand Down