1. Yuya Nishihara
  2. thg-qt-mq

Commits

Yuya Nishihara  committed b31abad

u8 patch

  • Participants
  • Parent commits 315f5ea
  • Branches default

Comments (0)

Files changed (2)

File enc-noutf8.diff

View file
+# HG changeset patch
+# Date 1382021388 -32400
+# Parent ed666228ff23c0f97dd95bff32f7204a3a0b54bc
+hglib: do not try utf-8 when converting localstr to unicode (fixes #3299)
+
+localstr must be encoded in locale encoding.  It's wrong to apply tounicode()
+to utf-8 byte sequence.
+
+diff --git a/tests/hglib_encoding_test.py b/tests/hglib_encoding_test.py
+--- a/tests/hglib_encoding_test.py
++++ b/tests/hglib_encoding_test.py
+@@ -82,6 +82,14 @@ def test_toutf_fallback():
+                   hglib.toutf(JAPANESE_KANA_I.encode('euc-jp')))
+ 
+ 
++@helpers.with_encoding('gbk')
++def test_gbk_roundtrip():
++    # gbk byte sequence can also be interpreted as utf-8 (issue #3299)
++    MOKU = u'\u76ee'
++    l = str(hglib.fromunicode(MOKU))
++    assert_equals(MOKU, hglib.tounicode(l))
++
++
+ @helpers.with_encoding('ascii')
+ def test_lossless_unicode_replaced():
+     l = hglib.fromunicode(JAPANESE_KANA_I, 'replace')
+diff --git a/tortoisehg/util/hglib.py b/tortoisehg/util/hglib.py
+--- a/tortoisehg/util/hglib.py
++++ b/tortoisehg/util/hglib.py
+@@ -37,11 +37,10 @@ def tounicode(s):
+         return s
+     if isinstance(s, encoding.localstr):
+         return s._utf8.decode('utf-8')
+-    for e in ('utf-8', _encoding):
+-        try:
+-            return s.decode(e, 'strict')
+-        except UnicodeDecodeError:
+-            pass
++    try:
++        return s.decode(_encoding, 'strict')
++    except UnicodeDecodeError:
++        pass
+     return s.decode(_fallbackencoding, 'replace')
+ 
+ def fromunicode(s, errors='strict'):

File series

View file
 repow-mqstatus.diff
 mq-multiselect.diff
+enc-noutf8.diff
 ci-checked.diff
 cmdui-height.diff
 cmdui-mark-setlogvisible.diff