forked from Perl/perl5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale.t
2780 lines (2398 loc) · 96.1 KB
/
locale.t
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!./perl -wT
# This tests plain 'use locale' and adorned 'use locale ":not_characters"'
# Because these pragmas are compile time, and I (khw) am trying to test
# without using 'eval' as much as possible, which might cloud the issue, the
# crucial parts of the code are duplicated in a block for each pragma.
# Unfortunately, many systems have defective locale definitions. This test
# file looks for both perl bugs and bugs in the system's locale definitions.
# It can be difficult to tease apart which is which. For the latter, there
# are tests that are based on the POSIX standard. A character isn't supposed
# to be both a space and graphic, for example. Another example is if a
# character is the uppercase of another, that other should be the lowercase of
# the first. Including tests for these allows you to test for defective
# locales, as described in perllocale. The way this file distinguishes
# between defective locales, and perl bugs is to see what percentage of
# locales fail a given test. If it's a lot, then it's more likely to be a
# perl bug; only a few, those particular locales are likely defective. In
# that case the failing tests are marked TODO. (They should be reported to
# the vendor, however; but it's not perl's problem.) In some cases, this
# script has caused tickets to be filed against perl which turn out to be the
# platform's bug, but a higher percentage of locales are failing than the
# built-in cut-off point. For those platforms, code has been added to
# increase the cut-off, so those platforms don't trigger failing test reports.
# Ideally, the platforms would get fixed and that code would be changed to
# only kick-in when run on versions that are earlier than the fixed one. But,
# this rarely happens in practice.
# To make a TODO test, add the string 'TODO' to its %test_names value
my $is_ebcdic = ord("A") == 193;
my $os = lc $^O;
no warnings 'locale'; # We test even weird locales; and do some scary things
# in ok locales
binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
unshift @INC, '.';
require './loc_tools.pl';
unless (locales_enabled('LC_CTYPE')) {
print "1..0\n";
exit;
}
$| = 1;
require Config; import Config;
}
use strict;
use feature 'fc';
# =1 adds debugging output; =2 increases the verbosity somewhat
our $debug = $ENV{PERL_DEBUG_FULL_TEST} // 0;
# Certain tests have been shown to be problematical for a few locales. Don't
# fail them unless at least this percentage of the tested locales fail.
# On AIX machines, many locales call a no-break space a graphic.
# (There aren't 1000 locales currently in existence, so 99.9 works)
# EBCDIC os390 has more locales fail than normal, because it has locales that
# move various critical characters like '['.
my $acceptable_failure_percentage = ($os =~ / ^ ( aix ) $ /x)
? 99.9
: ($os =~ / ^ ( os390 ) $ /x)
? 10
: 5;
# The list of test numbers of the problematic tests.
my %problematical_tests;
# If any %problematical_tests fails in one of these locales, it is
# considered a TODO.
my %known_bad_locales = (
irix => qr/ ^ (?: cs | hu | sk ) $/x,
darwin => qr/ ^ lt_LT.ISO8859 /ix,
os390 => qr/ ^ italian /ix,
netbsd => qr/\bISO8859-2\b/i,
# This may be the same bug as the cygwin below; it's
# generating malformed UTF-8 on the radix being
# mulit-byte
solaris => qr/ ^ ( ar_ | pa_ ) /x,
);
# cygwin isn't returning proper radix length in this locale, but supposedly to
# be fixed in later versions.
if ($os eq 'cygwin' && version->new(($Config{osvers} =~ /^(\d+(?:\.\d+)+)/)[0]) le v2.4.1) {
$known_bad_locales{'cygwin'} = qr/ ^ ps_AF /ix;
}
use Dumpvalue;
my $dumper = Dumpvalue->new(
tick => qq{"},
quoteHighBit => 0,
unctrl => "quote"
);
sub debug {
return unless $debug;
my($mess) = join "", '# ', @_;
chomp $mess;
print STDERR $dumper->stringify($mess,1), "\n";
}
sub note {
local $debug = 1;
debug @_;
}
sub debug_more {
return unless $debug > 1;
return debug(@_);
}
sub debugf {
printf STDERR @_ if $debug;
}
$a = 'abc %9';
my $test_num = 0;
sub ok {
my ($result, $message) = @_;
$message = "" unless defined $message;
print 'not ' unless ($result);
print "ok " . ++$test_num;
print " $message";
print "\n";
return ($result) ? 1 : 0;
}
sub skip {
return ok 1, "skipped: " . shift;
}
sub fail {
return ok 0, shift;
}
# First we'll do a lot of taint checking for locales.
# This is the easiest to test, actually, as any locale,
# even the default locale will taint under 'use locale'.
sub is_tainted { # hello, camel two.
no warnings 'uninitialized' ;
my $dummy;
local $@;
not eval { $dummy = join("", @_), kill 0; 1 }
}
sub check_taint ($;$) {
my $message_tail = $_[1] // "";
# Extra blanks are so aligns with taint_not output
$message_tail = ": $message_tail" if $message_tail;
ok is_tainted($_[0]), "verify that is tainted$message_tail";
}
sub check_taint_not ($;$) {
my $message_tail = $_[1] // "";
$message_tail = ": $message_tail" if $message_tail;
ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
}
foreach my $category (qw(ALL COLLATE CTYPE MESSAGES MONETARY NUMERIC TIME)) {
my $short_result = locales_enabled($category);
ok ($short_result == 0 || $short_result == 1,
"Verify locales_enabled('$category') returns 0 or 1");
debug("locales_enabled('$category') returned '$short_result'");
my $long_result = locales_enabled("LC_$category");
if (! ok ($long_result == $short_result,
" and locales_enabled('LC_$category') returns "
. "the same value")
) {
debug("locales_enabled('LC_$category') returned $long_result");
}
}
"\tb\t" =~ /^m?(\s)(.*)\1$/;
check_taint_not $&, "not tainted outside 'use locale'";
;
use locale; # engage locale and therefore locale taint.
# BE SURE TO COPY ANYTHING YOU ADD to these tests to the block below for
# ":notcharacters"
check_taint_not $a, '$a';
check_taint uc($a), 'uc($a)';
check_taint "\U$a", '"\U$a"';
check_taint ucfirst($a), 'ucfirst($a)';
check_taint "\u$a", '"\u$a"';
check_taint lc($a), 'lc($a)';
check_taint fc($a), 'fc($a)';
check_taint "\L$a", '"\L$a"';
check_taint "\F$a", '"\F$a"';
check_taint lcfirst($a), 'lcfirst($a)';
check_taint "\l$a", '"\l$a"';
check_taint_not sprintf('%e', 123.456), "sprintf('%e', 123.456)";
check_taint_not sprintf('%f', 123.456), "sprintf('%f', 123.456)";
check_taint_not sprintf('%g', 123.456), "sprintf('%g', 123.456)";
check_taint_not sprintf('%d', 123.456), "sprintf('%d', 123.456)";
check_taint_not sprintf('%x', 123.456), "sprintf('%x', 123.456)";
$_ = $a; # untaint $_
$_ = uc($a); # taint $_
check_taint $_, '$_ = uc($a)';
/(\w)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(\\w)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(\W)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(\\W)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(\s)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(\\s)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/(\S)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(\\S)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
"0" =~ /(\d)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(\\d)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/(\D)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(\\D)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/([[:alnum:]])/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /([[:alnum:]])/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/([[:^alnum:]])/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /([[:^alnum:]])/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
"a" =~ /(a)|(\w)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(a)|(\\w)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
ok($1 eq 'a', ("\t" x 5) . "\$1 is 'a'");
ok(! defined $2, ("\t" x 5) . "\$2 is undefined");
check_taint_not $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
"\N{CYRILLIC SMALL LETTER A}" =~ /(\N{CYRILLIC CAPITAL LETTER A})/i; # no tainting because no locale dependence
check_taint_not $&, "\$& from /(\\N{CYRILLIC CAPITAL LETTER A})/i";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
ok($1 eq "\N{CYRILLIC SMALL LETTER A}", ("\t" x 4) . "\t\$1 is 'small cyrillic a'");
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /./";
"(\N{KELVIN SIGN})" =~ /(\N{KELVIN SIGN})/i; # taints because depends on locale
check_taint $&, "\$& from /(\\N{KELVIN SIGN})/i";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
"a:" =~ /(.)\b(.)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(.)\\b(.)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /./";
"aa" =~ /(.)\B(.)/; # taint $&, $`, $', $+, $1.
check_taint $&, "\$& from /(.)\\B(.)/";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /./";
"aaa" =~ /(.).(\1)/i; # notaint because not locale dependent
check_taint_not $&, "\$ & from /(.).(\\1)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$ & from /./";
$_ = $a; # untaint $_
check_taint_not $_, 'untainting $_ works';
/(b)/; # this must not taint
check_taint_not $&, "\$ & from /(b)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
check_taint_not $_, 'untainting $_ works';
$b = uc($a); # taint $b
s/(.+)/$b/; # this must taint only the $_
check_taint $_, '$_ (wasn\'t tainted) from s/(.+)/$b/ where $b is tainted';
check_taint_not $&, "\t\$&";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
s/(.+)/b/; # this must not taint
check_taint_not $_, '$_ (wasn\'t tainted) from s/(.+)/b/';
check_taint_not $&, "\t\$&";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$b = $a; # untaint $b
($b = $a) =~ s/\w/$&/;
check_taint $b, '$b from ($b = $a) =~ s/\w/$&/'; # $b should be tainted.
check_taint_not $a, '$a from ($b = $a) =~ s/\w/$&/'; # $a should be not.
$_ = $a; # untaint $_
s/(\w)/\l$1/; # this must taint
check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\l$1/,'; # this must taint
check_taint $&, "\t\$&";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
s/(\w)/\L$1/; # this must taint
check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\L$1/,';
check_taint $&, "\t\$&";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
s/(\w)/\u$1/; # this must taint
check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\u$1/';
check_taint $&, "\t\$&";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
s/(\w)/\U$1/; # this must taint
check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\U$1/';
check_taint $&, "\t\$&";
check_taint $`, "\t\$`";
check_taint $', "\t\$'";
check_taint $+, "\t\$+";
check_taint $1, "\t\$1";
check_taint_not $2, "\t\$2";
# After all this tainting $a should be cool.
check_taint_not $a, '$a still not tainted';
"a" =~ /([a-z])/;
check_taint_not $1, '"a" =~ /([a-z])/';
"foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
# BE SURE TO COPY ANYTHING YOU ADD to the block below
{ # This is just the previous tests copied here with a different
# compile-time pragma.
use locale ':not_characters'; # engage restricted locale with different
# tainting rules
check_taint_not $a, '$a';
check_taint_not uc($a), 'uc($a)';
check_taint_not "\U$a", '"\U$a"';
check_taint_not ucfirst($a), 'ucfirst($a)';
check_taint_not "\u$a", '"\u$a"';
check_taint_not lc($a), 'lc($a)';
check_taint_not fc($a), 'fc($a)';
check_taint_not "\L$a", '"\L$a"';
check_taint_not "\F$a", '"\F$a"';
check_taint_not lcfirst($a), 'lcfirst($a)';
check_taint_not "\l$a", '"\l$a"';
check_taint_not sprintf('%e', 123.456), "sprintf('%e', 123.456)";
check_taint_not sprintf('%f', 123.456), "sprintf('%f', 123.456)";
check_taint_not sprintf('%g', 123.456), "sprintf('%g', 123.456)";
check_taint_not sprintf('%d', 123.456), "sprintf('%d', 123.456)";
check_taint_not sprintf('%x', 123.456), "sprintf('%x', 123.456)";
$_ = $a; # untaint $_
$_ = uc($a);
check_taint_not $_, '$_ = uc($a)';
/(\w)/;
check_taint_not $&, "\$& from /(\\w)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(\W)/;
check_taint_not $&, "\$& from /(\\W)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(\s)/;
check_taint_not $&, "\$& from /(\\s)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/(\S)/;
check_taint_not $&, "\$& from /(\\S)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
"0" =~ /(\d)/;
check_taint_not $&, "\$& from /(\\d)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/(\D)/;
check_taint_not $&, "\$& from /(\\D)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/([[:alnum:]])/;
check_taint_not $&, "\$& from /([[:alnum:]])/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
/([[:^alnum:]])/;
check_taint_not $&, "\$& from /([[:^alnum:]])/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
"a" =~ /(a)|(\w)/;
check_taint_not $&, "\$& from /(a)|(\\w)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
ok($1 eq 'a', ("\t" x 5) . "\$1 is 'a'");
ok(! defined $2, ("\t" x 5) . "\$2 is undefined");
check_taint_not $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
"\N{CYRILLIC SMALL LETTER A}" =~ /(\N{CYRILLIC CAPITAL LETTER A})/i;
check_taint_not $&, "\$& from /(\\N{CYRILLIC CAPITAL LETTER A})/i";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
ok($1 eq "\N{CYRILLIC SMALL LETTER A}", ("\t" x 4) . "\t\$1 is 'small cyrillic a'");
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /./";
"(\N{KELVIN SIGN})" =~ /(\N{KELVIN SIGN})/i;
check_taint_not $&, "\$& from /(\\N{KELVIN SIGN})/i";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /(.)/";
"a:" =~ /(.)\b(.)/;
check_taint_not $&, "\$& from /(.)\\b(.)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /./";
"aa" =~ /(.)\B(.)/;
check_taint_not $&, "\$& from /(.)\\B(.)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$& from /./";
"aaa" =~ /(.).(\1)/i; # notaint because not locale dependent
check_taint_not $&, "\$ & from /(.).(\\1)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
check_taint_not $3, "\t\$3";
/(.)/; # untaint $&, $`, $', $+, $1.
check_taint_not $&, "\$ & from /./";
$_ = $a; # untaint $_
check_taint_not $_, 'untainting $_ works';
/(b)/;
check_taint_not $&, "\$ & from /(b)/";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
check_taint_not $_, 'untainting $_ works';
s/(.+)/b/;
check_taint_not $_, '$_ (wasn\'t tainted) from s/(.+)/b/';
check_taint_not $&, "\t\$&";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$b = $a; # untaint $b
($b = $a) =~ s/\w/$&/;
check_taint_not $b, '$b from ($b = $a) =~ s/\w/$&/';
check_taint_not $a, '$a from ($b = $a) =~ s/\w/$&/';
$_ = $a; # untaint $_
s/(\w)/\l$1/;
check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\l$1/,'; # this must taint
check_taint_not $&, "\t\$&";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
s/(\w)/\L$1/;
check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\L$1/,';
check_taint_not $&, "\t\$&";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
s/(\w)/\u$1/;
check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\u$1/';
check_taint_not $&, "\t\$&";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
$_ = $a; # untaint $_
s/(\w)/\U$1/;
check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\U$1/';
check_taint_not $&, "\t\$&";
check_taint_not $`, "\t\$`";
check_taint_not $', "\t\$'";
check_taint_not $+, "\t\$+";
check_taint_not $1, "\t\$1";
check_taint_not $2, "\t\$2";
# After all this tainting $a should be cool.
check_taint_not $a, '$a still not tainted';
"a" =~ /([a-z])/;
check_taint_not $1, '"a" =~ /([a-z])/';
"foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
}
# Here are in scope of 'use locale'
# I think we've seen quite enough of taint.
# Let us do some *real* locale work now,
# unless setlocale() is missing (i.e. minitest).
# The test number before our first setlocale()
my $final_without_setlocale = $test_num;
# Find locales.
debug "Scanning for locales...\n";
require POSIX; import POSIX ':locale_h';
my $categories = [ 'LC_CTYPE', 'LC_NUMERIC', 'LC_ALL' ];
debug "Scanning for just compatible";
my @Locale = find_locales($categories);
debug "Scanning for even incompatible";
my @include_incompatible_locales = find_locales($categories,
'even incompatible locales');
# The locales included in the incompatible list that aren't in the compatible
# one.
my @incompatible_locales;
if (@Locale < @include_incompatible_locales) {
my %seen;
@seen{@Locale} = ();
foreach my $item (@include_incompatible_locales) {
push @incompatible_locales, $item unless exists $seen{$item};
}
# For each bad locale, switch into it to find out why it's incompatible
for my $bad_locale (@incompatible_locales) {
my @warnings;
use warnings 'locale';
local $SIG{__WARN__} = sub {
my $warning = $_[0];
chomp $warning;
push @warnings, ($warning =~ s/\n/\n# /sgr);
};
debug "Trying incompatible $bad_locale";
my $ret = setlocale(&POSIX::LC_CTYPE, $bad_locale);
my $message = "testing of locale '$bad_locale' is skipped";
if (@warnings) {
skip $message . ":\n# " . join "\n# ", @warnings;
}
elsif (! $ret) {
skip("$message:\n#"
. " setlocale(&POSIX::LC_CTYPE, '$bad_locale') failed");
}
else {
fail $message . ", because it is was found to be incompatible with"
. " Perl, but could not discern reason";
}
}
}
debug "Locales =\n";
for ( @Locale ) {
debug "$_\n";
}
unless (@Locale) {
print "1..$test_num\n";
exit;
}
setlocale(&POSIX::LC_ALL, "C");
my %posixes;
my %Problem;
my %Okay;
my %Known_bad_locale; # Failed test for a locale known to be bad
my %Testing;
my @Added_alpha; # Alphas that aren't in the C locale.
my %test_names;
sub disp_chars {
# This returns a display string denoting the input parameter @_, each
# entry of which is a single character in the range 0-255. The first part
# of the output is a string of the characters in @_ that are ASCII
# graphics, and hence unambiguously displayable. They are given by code
# point order. The second part is the remaining code points, the ordinals
# of which are each displayed as 2-digit hex. Blanks are inserted so as
# to keep anything from the first part looking like a 2-digit hex number.
no locale;
my @chars = sort { ord $a <=> ord $b } @_;
my $output = "";
my $range_start;
my $start_class;
push @chars, chr(258); # This sentinel simplifies the loop termination
# logic
foreach my $i (0 .. @chars - 1) {
my $char = $chars[$i];
my $range_end;
my $class;
# We avoid using [:posix:] classes, as these are being tested in this
# file. Each equivalence class below is for things that can appear in
# a range; those that can't be in a range have class -1. 0 for those
# which should be output in hex; and >0 for the other ranges
if ($char =~ /[A-Z]/) {
$class = 2;
}
elsif ($char =~ /[a-z]/) {
$class = 3;
}
elsif ($char =~ /[0-9]/) {
$class = 4;
}
# Uncomment to get literal punctuation displayed instead of hex
#elsif ($char =~ /[[\]!"#\$\%&\'()*+,.\/:\\;<=>?\@\^_`{|}~-]/) {
# $class = -1; # Punct never appears in a range
#}
else {
$class = 0; # Output in hex
}
if (! defined $range_start) {
if ($class < 0) {
$output .= " " . $char;
}
else {
$range_start = ord $char;
$start_class = $class;
}
} # A range ends if not consecutive, or the class-type changes
elsif (ord $char != ($range_end = ord($chars[$i-1])) + 1
|| $class != $start_class)
{
# Here, the current character is not in the range. This means the
# previous character must have been. Output the range up through
# that one.
my $range_length = $range_end - $range_start + 1;
if ($start_class > 0) {
$output .= " " . chr($range_start);
$output .= "-" . chr($range_end) if $range_length > 1;
}
else {
$output .= sprintf(" %02X", $range_start);
$output .= sprintf("-%02X", $range_end) if $range_length > 1;
}
# Handle the new current character, as potentially beginning a new
# range
undef $range_start;
redo;
}
}
$output =~ s/^ //;
return $output;
}
sub disp_str ($) {
my $string = shift;
# Displays the string unambiguously. ASCII printables are always output
# as-is, though perhaps separated by blanks from other characters. If
# entirely printable ASCII, just returns the string. Otherwise if valid
# UTF-8 it uses the character names for non-printable-ASCII. Otherwise it
# outputs hex for each non-ASCII-printable byte.
return $string if $string =~ / ^ [[:print:]]* $/xa;
my $result = "";
my $prev_was_punct = 1; # Beginning is considered punct
if (utf8::valid($string) && utf8::is_utf8($string)) {
use charnames ();
foreach my $char (split "", $string) {
# Keep punctuation adjacent to other characters; otherwise
# separate them with a blank
if ($char =~ /[[:punct:]]/a) {
$result .= $char;
$prev_was_punct = 1;
}
elsif ($char =~ /[[:print:]]/a) {
$result .= " " unless $prev_was_punct;
$result .= $char;
$prev_was_punct = 0;
}
else {
$result .= " " unless $prev_was_punct;
my $name = charnames::viacode(ord $char);
$result .= (defined $name) ? $name : ':unknown:';
$prev_was_punct = 0;
}
}
}
else {
use bytes;
foreach my $char (split "", $string) {
if ($char =~ /[[:punct:]]/a) {
$result .= $char;
$prev_was_punct = 1;
}
elsif ($char =~ /[[:print:]]/a) {
$result .= " " unless $prev_was_punct;
$result .= $char;
$prev_was_punct = 0;
}
else {
$result .= " " unless $prev_was_punct;
$result .= sprintf("%02X", ord $char);
$prev_was_punct = 0;
}
}
}
return $result;
}
sub report_result {
my ($Locale, $i, $pass_fail, $message) = @_;
if ($pass_fail) {
push @{$Okay{$i}}, $Locale;
}
else {
$message //= "";