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

Commit

Permalink
Fix #590 (#1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
slozier authored and slide committed Oct 17, 2016
1 parent ca9fefa commit 1bd6cca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Expand Up @@ -1764,6 +1764,10 @@ public static class StringOps {
}
#endif

#if FEATURE_ENCODING
private static DecoderFallback ReplacementFallback = new DecoderReplacementFallback("\ufffd");
#endif

internal static string DoDecode(CodeContext context, string s, string errors, string encoding, Encoding e) {
#if FEATURE_ENCODING
// CLR's encoder exceptions have a 1-1 mapping w/ Python's encoder exceptions
Expand All @@ -1774,7 +1778,7 @@ public static class StringOps {
case "backslashreplace":
case "xmlcharrefreplace":
case "strict": SetDecoderFallback(e, DecoderFallback.ExceptionFallback); break;
case "replace": SetDecoderFallback(e, DecoderFallback.ReplacementFallback); break;
case "replace": SetDecoderFallback(e, ReplacementFallback); break;
case "ignore": SetDecoderFallback(e, new PythonDecoderFallback(encoding, s, null)); break;
default:
SetDecoderFallback(e, new PythonDecoderFallback(encoding, s, LightExceptions.CheckAndThrow(PythonOps.LookupEncodingError(context, errors))));
Expand All @@ -1793,7 +1797,7 @@ public static class StringOps {
catch (NullReferenceException)
{
// bug in netstandard1.6, instead of failing try with a DecoderReplacementFallback
SetDecoderFallback(e, DecoderFallback.ReplacementFallback);
SetDecoderFallback(e, ReplacementFallback);
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions Languages/IronPython/Tests/test_unicode.py
Expand Up @@ -90,5 +90,8 @@ def test_cp34689():

Assert(caught)

def test_gh590():
AreEqual(unicode(''.join(chr(i) for i in range(0x80, 0x100)), 'ascii', 'replace'), u'\ufffd'*0x80)

#--MAIN------------------------------------------------------------------------
run_test(__name__)

0 comments on commit 1bd6cca

Please sign in to comment.