[commit: packages/text] master: fix utf8 error recovery for stream decoding (c976329)
git at git.haskell.org
git at git.haskell.org
Tue Aug 8 15:23:17 UTC 2017
Repository : ssh://git@git.haskell.org/text
On branch : master
Link : http://git.haskell.org/packages/text.git/commitdiff/c976329a5eaf1546390adff38625527e6b6f1d85
>---------------------------------------------------------------
commit c976329a5eaf1546390adff38625527e6b6f1d85
Author: Kubo Kovac <kuko at fb.com>
Date: Mon May 22 17:47:27 2017 +0100
fix utf8 error recovery for stream decoding
>---------------------------------------------------------------
c976329a5eaf1546390adff38625527e6b6f1d85
cbits/cbits.c | 6 ++----
tests/Tests/Properties.hs | 15 ++++++++++++++-
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/cbits/cbits.c b/cbits/cbits.c
index 029d7e8..9f46a41 100644
--- a/cbits/cbits.c
+++ b/cbits/cbits.c
@@ -207,10 +207,8 @@ _hs_text_decode_utf8_state(uint16_t *const dest, size_t *destoff,
uint32_t *codepoint0, uint32_t *state0)
{
uint8_t const *ret = _hs_text_decode_utf8_int(dest, destoff, src, srcend,
- codepoint0, state0);
- if (*state0 == UTF8_REJECT)
- ret -=1;
- return ret;
+ codepoint0, state0);
+ return *src;
}
/*
diff --git a/tests/Tests/Properties.hs b/tests/Tests/Properties.hs
index d490438..04156d9 100644
--- a/tests/Tests/Properties.hs
+++ b/tests/Tests/Properties.hs
@@ -193,6 +193,16 @@ t_decode_with_error3 =
t_decode_with_error4 =
E.decodeUtf8With (\_ _ -> Just 'x') (B.pack [0xF0, 97, 97, 97]) === "xaaa"
+t_decode_with_error2' =
+ case E.streamDecodeUtf8With (\_ _ -> Just 'x') (B.pack [0xC2, 97]) of
+ E.Some x _ _ -> x === "xa"
+t_decode_with_error3' =
+ case E.streamDecodeUtf8With (\_ _ -> Just 'x') (B.pack [0xC2, 97, 97]) of
+ E.Some x _ _ -> x === "xaa"
+t_decode_with_error4' =
+ case E.streamDecodeUtf8With (\_ _ -> Just 'x') (B.pack [0xC2, 97, 97, 97]) of
+ E.Some x _ _ -> x === "xaaa"
+
s_Eq s = (s==) `eq` ((S.streamList s==) . S.streamList)
where _types = s :: String
sf_Eq p s =
@@ -972,7 +982,10 @@ tests =
testGroup "error recovery" [
testProperty "t_decode_with_error2" t_decode_with_error2,
testProperty "t_decode_with_error3" t_decode_with_error3,
- testProperty "t_decode_with_error4" t_decode_with_error4
+ testProperty "t_decode_with_error4" t_decode_with_error4,
+ testProperty "t_decode_with_error2'" t_decode_with_error2',
+ testProperty "t_decode_with_error3'" t_decode_with_error3',
+ testProperty "t_decode_with_error4'" t_decode_with_error4'
]
],
More information about the ghc-commits
mailing list