@@ -607,8 +607,21 @@ new_spec_unpack_test_() ->
607607 ]}].
608608
609609unpack_str_validation_test_ () ->
610+ String = unicode :characters_to_binary (" あいうえおかきくけこさしすせそ" " abcdefghijklmnopqrstuv" ),
611+ InvalidStr = <<255 ,255 ,255 ,255 , 255 ,255 ,255 ,255 , 255 ,255 ,255 ,255 , 255 ,255 ,255 ,255 >>,
612+ WrongPack = <<16#D9 , 16 , InvalidStr /binary >>,
613+ Packed = msgpack :pack (String , [{spec ,new },{pack_str ,from_binary }]),
614+ NoValidation = [{spec ,new },{unpack_str ,as_binary },{validate_string ,false }],
615+ DoValidation = [{spec ,new },{unpack_str ,as_binary },{validate_string ,true }],
610616 [{" validate_string false, on unpacking" ,
611- []},
617+ [? _assertEqual ({ok , String }, msgpack :unpack (Packed , NoValidation )),
618+ ? _assertEqual ({ok , InvalidStr }, msgpack :unpack (WrongPack , NoValidation ))]},
612619 {" validate_string true, on unpacking" ,
613- []}
620+ [? _assertEqual ({ok , String }, msgpack :unpack (Packed , DoValidation )),
621+ ? _assertEqual ({error , {invalid_string , InvalidStr }}, msgpack :unpack (WrongPack , DoValidation )),
622+
623+ % % TODO: this should be invalid string
624+ ? _assertEqual ({error , {badarg , binary_to_list (InvalidStr )}},
625+ msgpack :unpack (binary_to_list (InvalidStr ),
626+ [{spec ,new },{unpack_str ,from_list },{validate_string ,true }]))]}
614627 ].
0 commit comments