on master help sign in
Merge from 1.0 branch again
commitbebb3406ac8bc6d2d21db51ec4a2ef891f0ce5af authorBryan O'Sullivan <bos@serpentine.com> dateMon 30 Dec 2013, 15:31 (13 years ago) parent7bceda0200a2cb
2 files changed+19−1
.hgtags+1 tests/Tests/Properties.hs+18−1
.hgtags+1
@@ -43,3 +43,4 @@ b75d3041d275e8e76b26605b0d426a572ddf1249 0.11.1.3
43437fa79662b66aade97fe49394977213fe6432942e 0.11.3.0
4444d99cd091cdf71ce807a4255f6cc509c3154f51ea 0.11.3.1
454531f57612fd425d1bb56352ce6b79e41ce6699a45 1.0.0.0
46+7cba97c86467c1881dfced68613891f3c65561b0 1.0.0.1
tests/Tests/Properties.hs+18−1
@@ -9,19 +9,21 @@ module Tests.Properties
99 tests
1010 ) where
1111
12−import Test.QuickCheck
12+import Test.QuickCheck hiding ((.&.))
1313import Test.QuickCheck.Monadic
1414import Text.Show.Functions ()
1515
1616import Control.Applicative ((<$>), (<*>))
1717import Control.Arrow ((***), second)
1818import Control.Exception (catch)
19+import Data.Bits ((.&.))
1920import Data.Char (chr, isDigit, isHexDigit, isLower, isSpace, isUpper, ord)
2021import Data.Int (Int8, Int16, Int32, Int64)
2122import Data.Monoid (Monoid(..))
2223import Data.String (fromString)
2324import Data.Text.Encoding.Error
2425import Data.Text.Foreign
26+import Data.Text.Internal.Encoding.Utf8
2527import Data.Text.Internal.Fusion.Size
2628import Data.Text.Lazy.Read as TL
2729import Data.Text.Read as T
@@ -145,6 +147,11 @@ genInvalidUTF8 = B.pack <$> oneof [
145147 (:) <$> choose (0xC0, 0xC1) <*> upTo 1 contByte
146148 -- invalid leading byte of a 4-byte sequence
147149 , (:) <$> choose (0xF5, 0xFF) <*> upTo 3 contByte
150+ -- 4-byte sequence greater than U+10FFFF
151+ , do k <- choose (0x11, 0x1F)
152+ let w0 = 0xF0 + (k `Bits.shiftR` 2)
153+ w1 = 0x80 + ((k .&. 3) `Bits.shiftL` 4)
154+ ([w0,w1]++) <$> vectorOf 2 contByte
148155 -- continuation bytes without a start byte
149156 , listOf1 contByte
150157 -- short 2-byte sequence
@@ -153,6 +160,16 @@ genInvalidUTF8 = B.pack <$> oneof [
153160 , (:) <$> choose (0xE0, 0xEF) <*> upTo 1 contByte
154161 -- short 4-byte sequence
155162 , (:) <$> choose (0xF0, 0xF4) <*> upTo 2 contByte
163+ -- overlong encoding
164+ , do k <- choose (0,0xFFFF)
165+ let c = chr k
166+ case k of
167+ _ | k < 0x80 -> oneof [ let (w,x) = ord2 c in return [w,x]
168+ , let (w,x,y) = ord3 c in return [w,x,y]
169+ , let (w,x,y,z) = ord4 c in return [w,x,y,z] ]
170+ | k < 0x7FF -> oneof [ let (w,x,y) = ord3 c in return [w,x,y]
171+ , let (w,x,y,z) = ord4 c in return [w,x,y,z] ]
172+ | otherwise -> let (w,x,y,z) = ord4 c in return [w,x,y,z]
156173 ]
157174 where
158175 contByte = (0x80 +) <$> choose (0, 0x3f)