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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!./perl
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
}
##Literal test count since evals below can fail
plan tests => 13;
$a = 'ab' . 'c'; # compile time
$b = 'def';
$c = $a . $b;
is( $c, 'abcdef', 'compile time concatenation' );
$c .= 'xyz';
is( $c, 'abcdefxyz', 'concat to self');
$_ = $a;
$_ .= $b;
is( $_, 'abcdef', 'concat using $_');
# test that when right argument of concat is UTF8, and is the same
# variable as the target, and the left argument is not UTF8, it no
# longer frees the wrong string.
{
sub r2 {
my $string = '';
$string .= pack("U0a*", 'mnopqrstuvwx');
$string = "abcdefghijkl$string";
}
isnt(r2(), '', 'UTF8 concat does not free the wrong string');
isnt(r2(), '', 'second check');
}
# test that nul bytes get copied
{
my ($a, $ab) = ("a", "a\0b");
my ($ua, $uab) = map pack("U0a*", $_), $a, $ab;
my $ub = pack("U0a*", 'b');
#aa\0b
my $t1 = $a; $t1 .= $ab;
like( $t1, qr/b/, 'null bytes do not stop string copy, aa\0b');
#a\0a\0b
my $t2 = $a; $t2 .= $uab;
ok( eval '$t2 =~ /$ub/', '... a\0a\0b' );
#\0aa\0b
my $t3 = $ua; $t3 .= $ab;
ok( eval '$t3 =~ /$ub/', '... \0aa\0b' );
my $t4 = $ua; $t4 .= $uab;
ok( eval '$t4 =~ /$ub/', '... \0a\0a\0b' );
my $t5 = $a; $t5 = $ab . $t5;
like( $t5, qr/$ub/, '... a\0ba' );
my $t6 = $a; $t6 = $uab . $t6;
ok( eval '$t6 =~ /$ub/', '... \0a\0ba' );
my $t7 = $ua; $t7 = $ab . $t7;
like( $t7, qr/$ub/, '... a\0b\0a' );
my $t8 = $ua; $t8 = $uab . $t8;
ok( eval '$t8 =~ /$ub/', '... \0a\0b\0a' );
}
|