File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,3 +90,30 @@ fn test_null_separator() {
9090 . stdout_is ( "FOO\x00 VALUE\x00 " ) ;
9191 }
9292}
93+
94+ #[ test]
95+ #[ cfg( unix) ]
96+ #[ cfg( not( any( target_os = "freebsd" , target_os = "android" , target_os = "openbsd" ) ) ) ]
97+ fn test_non_utf8_value ( ) {
98+ use std:: ffi:: OsStr ;
99+ use std:: os:: unix:: ffi:: OsStrExt ;
100+ // Environment variable values can contain non-UTF-8 bytes on Unix.
101+ // printenv should output them correctly, matching GNU behavior.
102+ // Reproduces: LD_PRELOAD=$'/tmp/lib.so\xff' printenv LD_PRELOAD
103+ let value_with_invalid_utf8 = OsStr :: from_bytes ( b"/tmp/lib.so\xff " ) ;
104+
105+ let result = new_ucmd ! ( )
106+ . env ( "LD_PRELOAD" , value_with_invalid_utf8)
107+ . arg ( "LD_PRELOAD" )
108+ . run ( ) ;
109+
110+ // Use byte-based assertions to avoid UTF-8 conversion issues
111+ // when the test framework tries to format error messages
112+ assert ! (
113+ result. succeeded( ) ,
114+ "Command failed with exit code: {:?}, stderr: {:?}" ,
115+ result. code( ) ,
116+ String :: from_utf8_lossy( result. stderr( ) )
117+ ) ;
118+ result. stdout_is_bytes ( b"/tmp/lib.so\xff \n " ) ;
119+ }
You can’t perform that action at this time.
0 commit comments