Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
added dedicated test
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljasinski committed Feb 5, 2014
1 parent 13af526 commit bba3817
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Languages/IronPython/IronPython.Modules/_codecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,12 @@ private static PythonTuple DoDecode(Encoding encoding, object input, string erro
}

#if FEATURE_ENCODING // DecoderFallback
var utf8Workaround = encoding == Encoding.UTF8 && DotNet;
encoding = (Encoding)encoding.Clone();
ExceptionFallBack fallback = null;
if (fAlwaysThrow) {
encoding.DecoderFallback = DecoderFallback.ExceptionFallback;
} else {
var utf8Workaround = encoding == Encoding.UTF8 && DotNet;
fallback = new ExceptionFallBack(bytes, utf8Workaround);
encoding.DecoderFallback = fallback;
}
Expand Down
20 changes: 20 additions & 0 deletions Languages/IronPython/Tests/modules/io_related/codecs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,26 @@ def test_utf_8_decode():
AreEqual(new_str, u'abc')
AreEqual(size, 3)


def test_cp34951():
def internal_cp34951(sample1):
AreEqual(codecs.utf_8_decode(sample1), (u'12\u20ac\x0a', 6))
sample1 = sample1[:-1] # 12<euro>
AreEqual(codecs.utf_8_decode(sample1), (u'12\u20ac', 5))
sample1 = sample1[:-1] # 12<uncomplete euro>
AreEqual(codecs.utf_8_decode(sample1), (u'12', 2))

sample1 = sample1 + 'x7f' # makes it invalid
try:
r = codecs.utf_8_decode(sample1)
Assert(False, "expected UncodeDecodeError not raised")
except Exception as e:
AreEqual(type(e), UnicodeDecodeError)

internal_cp34951(b'\x31\x32\xe2\x82\xac\x0a') # 12<euro><cr>
internal_cp34951(b'\xef\xbb\xbf\x31\x32\xe2\x82\xac\x0a') # <BOM>12<euro><cr>


def test_utf_8_encode():
'''
'''
Expand Down

0 comments on commit bba3817

Please sign in to comment.