File: Unicode_trailing_nul.t

package info (click to toggle)
perl 5.36.0-7%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 120,064 kB
  • sloc: ansic: 650,199; perl: 478,052; sh: 70,710; pascal: 8,435; xml: 2,428; yacc: 1,230; makefile: 1,175; cpp: 208; lisp: 1
file content (26 lines) | stat: -rw-r--r-- 731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use strict;
use Test::More;

use Encode;
use File::Temp;
use File::Spec;

# This test relies on https://github.com/Perl/perl5/issues/10623;
# if that bug is ever fixed then this test may never fail again.

my $foo = Encode::decode("UTF-16LE", "/\0v\0a\0r\0/\0f\0f\0f\0f\0f\0f\0/\0u\0s\0e\0r\0s\0/\0s\0u\0p\0e\0r\0m\0a\0n\0");

my ($fh, $path) = File::Temp::tempfile( CLEANUP => 1 );

note "temp file: $path";

# Perl gives the internal PV to exec .. which is buggy/wrong but
# useful here:
system( $^X, '-e', "open my \$fh, '>>', '$path' or die \$!; print {\$fh} \$ARGV[0]", $foo );
die if $?;

my $output = do { local $/; <$fh> };

is( $output, "/var/ffffff/users/superman", 'UTF-16 decodes with trailing NUL' );

done_testing();