File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1100,7 +1100,7 @@ impl RString {
11001100
11011101 unsafe fn as_str_unconstrained < ' a > ( self ) -> Result < & ' a str , Error > {
11021102 self . test_as_str_unconstrained ( ) . ok_or_else ( || {
1103- let msg: Cow < ' static , str > = if self . is_utf8_compatible_encoding ( ) {
1103+ let msg: Cow < ' static , str > = if ! self . is_utf8_compatible_encoding ( ) {
11041104 format ! (
11051105 "expected utf-8, got {}" ,
11061106 RbEncoding :: from( self . enc_get( ) ) . name( )
Original file line number Diff line number Diff line change @@ -10,4 +10,14 @@ fn it_converts_to_utf8_string() {
1010 let s = String :: try_convert ( val) . unwrap ( ) ;
1111
1212 assert_eq ! ( "café" , s) ;
13+
14+ let val: Value = magnus:: eval!( r#""\xFF\xFF""# ) . unwrap ( ) ;
15+ let err = String :: try_convert ( val) . unwrap_err ( ) ;
16+
17+ let expected_error = "invalid byte sequence in UTF-8" ;
18+ assert ! (
19+ err. to_string( ) . contains( expected_error) ,
20+ "Expected \" {}\" to contain \" {expected_error}\" but it didn't" ,
21+ err. to_string( )
22+ ) ;
1323}
You can’t perform that action at this time.
0 commit comments