3 # This tests plain 'use locale' and adorned 'use locale ":not_characters"'
4 # Because these pragmas are compile time, and I (khw) am trying to test
5 # without using 'eval' as much as possible, which might cloud the issue, the
6 # crucial parts of the code are duplicated in a block for each pragma.
8 # To make a TODO test, add the string 'TODO' to its %test_names value
10 my $is_ebcdic = ord("A") == 193;
12 no warnings 'locale'; # We test even weird locales; and do some scary things
15 binmode STDOUT, ':utf8';
16 binmode STDERR, ':utf8';
22 require './loc_tools.pl';
23 unless (locales_enabled('LC_CTYPE')) {
28 require Config; import Config;
32 use feature 'fc', 'postderef';
34 # =1 adds debugging output; =2 increases the verbosity somewhat
35 my $debug = $ENV{PERL_DEBUG_FULL_TEST} // 0;
37 # Certain tests have been shown to be problematical for a few locales. Don't
38 # fail them unless at least this percentage of the tested locales fail.
39 # On AIX machines, many locales call a no-break space a graphic.
40 # (There aren't 1000 locales currently in existence, so 99.9 works)
41 my $acceptable_failure_percentage = ($^O =~ / ^ ( AIX ) $ /ix)
45 # The list of test numbers of the problematic tests.
46 my %problematical_tests;
48 # If any %problematical_tests fails in one of these locales, it is
50 my %known_bad_locales = (
51 irix => qr/ ^ (?: cs | hu | sk ) $/x,
52 darwin => qr/ ^ lt_LT.ISO8859 /ix,
53 os390 => qr/ ^ italian /ix,
58 my $dumper = Dumpvalue->new(
65 my($mess) = join "", '# ', @_;
67 print STDERR $dumper->stringify($mess,1), "\n";
71 return unless $debug > 1;
76 printf STDERR @_ if $debug;
84 my ($result, $message) = @_;
85 $message = "" unless defined $message;
87 print 'not ' unless ($result);
88 print "ok " . ++$test_num;
91 return ($result) ? 1 : 0;
94 # First we'll do a lot of taint checking for locales.
95 # This is the easiest to test, actually, as any locale,
96 # even the default locale will taint under 'use locale'.
98 sub is_tainted { # hello, camel two.
99 no warnings 'uninitialized' ;
102 not eval { $dummy = join("", @_), kill 0; 1 }
105 sub check_taint ($;$) {
106 my $message_tail = $_[1] // "";
108 # Extra blanks are so aligns with taint_not output
109 $message_tail = ": $message_tail" if $message_tail;
110 ok is_tainted($_[0]), "verify that is tainted$message_tail";
113 sub check_taint_not ($;$) {
114 my $message_tail = $_[1] // "";
115 $message_tail = ": $message_tail" if $message_tail;
116 ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
119 foreach my $category (qw(ALL COLLATE CTYPE MESSAGES MONETARY NUMERIC TIME)) {
120 my $short_result = locales_enabled($category);
121 ok ($short_result == 0 || $short_result == 1,
122 "Verify locales_enabled('$category') returns 0 or 1");
123 debug("locales_enabled('$category') returned '$short_result'");
124 my $long_result = locales_enabled("LC_$category");
125 if (! ok ($long_result == $short_result,
126 " and locales_enabled('LC_$category') returns "
129 debug("locales_enabled('LC_$category') returned $long_result");
133 "\tb\t" =~ /^m?(\s)(.*)\1$/;
134 check_taint_not $&, "not tainted outside 'use locale'";
137 use locale; # engage locale and therefore locale taint.
139 # BE SURE TO COPY ANYTHING YOU ADD to these tests to the block below for
142 check_taint_not $a, '$a';
144 check_taint uc($a), 'uc($a)';
145 check_taint "\U$a", '"\U$a"';
146 check_taint ucfirst($a), 'ucfirst($a)';
147 check_taint "\u$a", '"\u$a"';
148 check_taint lc($a), 'lc($a)';
149 check_taint fc($a), 'fc($a)';
150 check_taint "\L$a", '"\L$a"';
151 check_taint "\F$a", '"\F$a"';
152 check_taint lcfirst($a), 'lcfirst($a)';
153 check_taint "\l$a", '"\l$a"';
155 check_taint_not sprintf('%e', 123.456), "sprintf('%e', 123.456)";
156 check_taint_not sprintf('%f', 123.456), "sprintf('%f', 123.456)";
157 check_taint_not sprintf('%g', 123.456), "sprintf('%g', 123.456)";
158 check_taint_not sprintf('%d', 123.456), "sprintf('%d', 123.456)";
159 check_taint_not sprintf('%x', 123.456), "sprintf('%x', 123.456)";
161 $_ = $a; # untaint $_
163 $_ = uc($a); # taint $_
165 check_taint $_, '$_ = uc($a)';
167 /(\w)/; # taint $&, $`, $', $+, $1.
168 check_taint $&, "\$& from /(\\w)/";
169 check_taint $`, "\t\$`";
170 check_taint $', "\t\$'";
171 check_taint $+, "\t\$+";
172 check_taint $1, "\t\$1";
173 check_taint_not $2, "\t\$2";
175 /(.)/; # untaint $&, $`, $', $+, $1.
176 check_taint_not $&, "\$& from /(.)/";
177 check_taint_not $`, "\t\$`";
178 check_taint_not $', "\t\$'";
179 check_taint_not $+, "\t\$+";
180 check_taint_not $1, "\t\$1";
181 check_taint_not $2, "\t\$2";
183 /(\W)/; # taint $&, $`, $', $+, $1.
184 check_taint $&, "\$& from /(\\W)/";
185 check_taint $`, "\t\$`";
186 check_taint $', "\t\$'";
187 check_taint $+, "\t\$+";
188 check_taint $1, "\t\$1";
189 check_taint_not $2, "\t\$2";
191 /(.)/; # untaint $&, $`, $', $+, $1.
192 check_taint_not $&, "\$& from /(.)/";
193 check_taint_not $`, "\t\$`";
194 check_taint_not $', "\t\$'";
195 check_taint_not $+, "\t\$+";
196 check_taint_not $1, "\t\$1";
197 check_taint_not $2, "\t\$2";
199 /(\s)/; # taint $&, $`, $', $+, $1.
200 check_taint $&, "\$& from /(\\s)/";
201 check_taint $`, "\t\$`";
202 check_taint $', "\t\$'";
203 check_taint $+, "\t\$+";
204 check_taint $1, "\t\$1";
205 check_taint_not $2, "\t\$2";
207 /(.)/; # untaint $&, $`, $', $+, $1.
208 check_taint_not $&, "\$& from /(.)/";
210 /(\S)/; # taint $&, $`, $', $+, $1.
211 check_taint $&, "\$& from /(\\S)/";
212 check_taint $`, "\t\$`";
213 check_taint $', "\t\$'";
214 check_taint $+, "\t\$+";
215 check_taint $1, "\t\$1";
216 check_taint_not $2, "\t\$2";
218 /(.)/; # untaint $&, $`, $', $+, $1.
219 check_taint_not $&, "\$& from /(.)/";
221 "0" =~ /(\d)/; # taint $&, $`, $', $+, $1.
222 check_taint $&, "\$& from /(\\d)/";
223 check_taint $`, "\t\$`";
224 check_taint $', "\t\$'";
225 check_taint $+, "\t\$+";
226 check_taint $1, "\t\$1";
227 check_taint_not $2, "\t\$2";
229 /(.)/; # untaint $&, $`, $', $+, $1.
230 check_taint_not $&, "\$& from /(.)/";
232 /(\D)/; # taint $&, $`, $', $+, $1.
233 check_taint $&, "\$& from /(\\D)/";
234 check_taint $`, "\t\$`";
235 check_taint $', "\t\$'";
236 check_taint $+, "\t\$+";
237 check_taint $1, "\t\$1";
238 check_taint_not $2, "\t\$2";
240 /(.)/; # untaint $&, $`, $', $+, $1.
241 check_taint_not $&, "\$& from /(.)/";
243 /([[:alnum:]])/; # taint $&, $`, $', $+, $1.
244 check_taint $&, "\$& from /([[:alnum:]])/";
245 check_taint $`, "\t\$`";
246 check_taint $', "\t\$'";
247 check_taint $+, "\t\$+";
248 check_taint $1, "\t\$1";
249 check_taint_not $2, "\t\$2";
251 /(.)/; # untaint $&, $`, $', $+, $1.
252 check_taint_not $&, "\$& from /(.)/";
254 /([[:^alnum:]])/; # taint $&, $`, $', $+, $1.
255 check_taint $&, "\$& from /([[:^alnum:]])/";
256 check_taint $`, "\t\$`";
257 check_taint $', "\t\$'";
258 check_taint $+, "\t\$+";
259 check_taint $1, "\t\$1";
260 check_taint_not $2, "\t\$2";
262 "a" =~ /(a)|(\w)/; # taint $&, $`, $', $+, $1.
263 check_taint $&, "\$& from /(a)|(\\w)/";
264 check_taint $`, "\t\$`";
265 check_taint $', "\t\$'";
266 check_taint $+, "\t\$+";
267 check_taint $1, "\t\$1";
268 ok($1 eq 'a', ("\t" x 5) . "\$1 is 'a'");
269 ok(! defined $2, ("\t" x 5) . "\$2 is undefined");
270 check_taint_not $2, "\t\$2";
271 check_taint_not $3, "\t\$3";
273 /(.)/; # untaint $&, $`, $', $+, $1.
274 check_taint_not $&, "\$& from /(.)/";
276 "\N{CYRILLIC SMALL LETTER A}" =~ /(\N{CYRILLIC CAPITAL LETTER A})/i; # no tainting because no locale dependence
277 check_taint_not $&, "\$& from /(\\N{CYRILLIC CAPITAL LETTER A})/i";
278 check_taint_not $`, "\t\$`";
279 check_taint_not $', "\t\$'";
280 check_taint_not $+, "\t\$+";
281 check_taint_not $1, "\t\$1";
282 ok($1 eq "\N{CYRILLIC SMALL LETTER A}", ("\t" x 4) . "\t\$1 is 'small cyrillic a'");
283 check_taint_not $2, "\t\$2";
285 /(.)/; # untaint $&, $`, $', $+, $1.
286 check_taint_not $&, "\$& from /./";
288 "(\N{KELVIN SIGN})" =~ /(\N{KELVIN SIGN})/i; # taints because depends on locale
289 check_taint $&, "\$& from /(\\N{KELVIN SIGN})/i";
290 check_taint $`, "\t\$`";
291 check_taint $', "\t\$'";
292 check_taint $+, "\t\$+";
293 check_taint $1, "\t\$1";
294 check_taint_not $2, "\t\$2";
296 /(.)/; # untaint $&, $`, $', $+, $1.
297 check_taint_not $&, "\$& from /(.)/";
299 "a:" =~ /(.)\b(.)/; # taint $&, $`, $', $+, $1.
300 check_taint $&, "\$& from /(.)\\b(.)/";
301 check_taint $`, "\t\$`";
302 check_taint $', "\t\$'";
303 check_taint $+, "\t\$+";
304 check_taint $1, "\t\$1";
305 check_taint $2, "\t\$2";
306 check_taint_not $3, "\t\$3";
308 /(.)/; # untaint $&, $`, $', $+, $1.
309 check_taint_not $&, "\$& from /./";
311 "aa" =~ /(.)\B(.)/; # taint $&, $`, $', $+, $1.
312 check_taint $&, "\$& from /(.)\\B(.)/";
313 check_taint $`, "\t\$`";
314 check_taint $', "\t\$'";
315 check_taint $+, "\t\$+";
316 check_taint $1, "\t\$1";
317 check_taint $2, "\t\$2";
318 check_taint_not $3, "\t\$3";
320 /(.)/; # untaint $&, $`, $', $+, $1.
321 check_taint_not $&, "\$& from /./";
323 "aaa" =~ /(.).(\1)/i; # notaint because not locale dependent
324 check_taint_not $&, "\$ & from /(.).(\\1)/";
325 check_taint_not $`, "\t\$`";
326 check_taint_not $', "\t\$'";
327 check_taint_not $+, "\t\$+";
328 check_taint_not $1, "\t\$1";
329 check_taint_not $2, "\t\$2";
330 check_taint_not $3, "\t\$3";
332 /(.)/; # untaint $&, $`, $', $+, $1.
333 check_taint_not $&, "\$ & from /./";
335 $_ = $a; # untaint $_
337 check_taint_not $_, 'untainting $_ works';
339 /(b)/; # this must not taint
340 check_taint_not $&, "\$ & from /(b)/";
341 check_taint_not $`, "\t\$`";
342 check_taint_not $', "\t\$'";
343 check_taint_not $+, "\t\$+";
344 check_taint_not $1, "\t\$1";
345 check_taint_not $2, "\t\$2";
347 $_ = $a; # untaint $_
349 check_taint_not $_, 'untainting $_ works';
351 $b = uc($a); # taint $b
352 s/(.+)/$b/; # this must taint only the $_
354 check_taint $_, '$_ (wasn\'t tainted) from s/(.+)/$b/ where $b is tainted';
355 check_taint_not $&, "\t\$&";
356 check_taint_not $`, "\t\$`";
357 check_taint_not $', "\t\$'";
358 check_taint_not $+, "\t\$+";
359 check_taint_not $1, "\t\$1";
360 check_taint_not $2, "\t\$2";
362 $_ = $a; # untaint $_
364 s/(.+)/b/; # this must not taint
365 check_taint_not $_, '$_ (wasn\'t tainted) from s/(.+)/b/';
366 check_taint_not $&, "\t\$&";
367 check_taint_not $`, "\t\$`";
368 check_taint_not $', "\t\$'";
369 check_taint_not $+, "\t\$+";
370 check_taint_not $1, "\t\$1";
371 check_taint_not $2, "\t\$2";
373 $b = $a; # untaint $b
375 ($b = $a) =~ s/\w/$&/;
376 check_taint $b, '$b from ($b = $a) =~ s/\w/$&/'; # $b should be tainted.
377 check_taint_not $a, '$a from ($b = $a) =~ s/\w/$&/'; # $a should be not.
379 $_ = $a; # untaint $_
381 s/(\w)/\l$1/; # this must taint
382 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\l$1/,'; # this must taint
383 check_taint $&, "\t\$&";
384 check_taint $`, "\t\$`";
385 check_taint $', "\t\$'";
386 check_taint $+, "\t\$+";
387 check_taint $1, "\t\$1";
388 check_taint_not $2, "\t\$2";
390 $_ = $a; # untaint $_
392 s/(\w)/\L$1/; # this must taint
393 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\L$1/,';
394 check_taint $&, "\t\$&";
395 check_taint $`, "\t\$`";
396 check_taint $', "\t\$'";
397 check_taint $+, "\t\$+";
398 check_taint $1, "\t\$1";
399 check_taint_not $2, "\t\$2";
401 $_ = $a; # untaint $_
403 s/(\w)/\u$1/; # this must taint
404 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\u$1/';
405 check_taint $&, "\t\$&";
406 check_taint $`, "\t\$`";
407 check_taint $', "\t\$'";
408 check_taint $+, "\t\$+";
409 check_taint $1, "\t\$1";
410 check_taint_not $2, "\t\$2";
412 $_ = $a; # untaint $_
414 s/(\w)/\U$1/; # this must taint
415 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\U$1/';
416 check_taint $&, "\t\$&";
417 check_taint $`, "\t\$`";
418 check_taint $', "\t\$'";
419 check_taint $+, "\t\$+";
420 check_taint $1, "\t\$1";
421 check_taint_not $2, "\t\$2";
423 # After all this tainting $a should be cool.
425 check_taint_not $a, '$a still not tainted';
428 check_taint_not $1, '"a" =~ /([a-z])/';
429 "foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
430 check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
432 # BE SURE TO COPY ANYTHING YOU ADD to the block below
434 { # This is just the previous tests copied here with a different
435 # compile-time pragma.
437 use locale ':not_characters'; # engage restricted locale with different
439 check_taint_not $a, '$a';
441 check_taint_not uc($a), 'uc($a)';
442 check_taint_not "\U$a", '"\U$a"';
443 check_taint_not ucfirst($a), 'ucfirst($a)';
444 check_taint_not "\u$a", '"\u$a"';
445 check_taint_not lc($a), 'lc($a)';
446 check_taint_not fc($a), 'fc($a)';
447 check_taint_not "\L$a", '"\L$a"';
448 check_taint_not "\F$a", '"\F$a"';
449 check_taint_not lcfirst($a), 'lcfirst($a)';
450 check_taint_not "\l$a", '"\l$a"';
452 check_taint_not sprintf('%e', 123.456), "sprintf('%e', 123.456)";
453 check_taint_not sprintf('%f', 123.456), "sprintf('%f', 123.456)";
454 check_taint_not sprintf('%g', 123.456), "sprintf('%g', 123.456)";
455 check_taint_not sprintf('%d', 123.456), "sprintf('%d', 123.456)";
456 check_taint_not sprintf('%x', 123.456), "sprintf('%x', 123.456)";
458 $_ = $a; # untaint $_
462 check_taint_not $_, '$_ = uc($a)';
465 check_taint_not $&, "\$& from /(\\w)/";
466 check_taint_not $`, "\t\$`";
467 check_taint_not $', "\t\$'";
468 check_taint_not $+, "\t\$+";
469 check_taint_not $1, "\t\$1";
470 check_taint_not $2, "\t\$2";
472 /(.)/; # untaint $&, $`, $', $+, $1.
473 check_taint_not $&, "\$& from /(.)/";
474 check_taint_not $`, "\t\$`";
475 check_taint_not $', "\t\$'";
476 check_taint_not $+, "\t\$+";
477 check_taint_not $1, "\t\$1";
478 check_taint_not $2, "\t\$2";
481 check_taint_not $&, "\$& from /(\\W)/";
482 check_taint_not $`, "\t\$`";
483 check_taint_not $', "\t\$'";
484 check_taint_not $+, "\t\$+";
485 check_taint_not $1, "\t\$1";
486 check_taint_not $2, "\t\$2";
488 /(.)/; # untaint $&, $`, $', $+, $1.
489 check_taint_not $&, "\$& from /(.)/";
490 check_taint_not $`, "\t\$`";
491 check_taint_not $', "\t\$'";
492 check_taint_not $+, "\t\$+";
493 check_taint_not $1, "\t\$1";
494 check_taint_not $2, "\t\$2";
497 check_taint_not $&, "\$& from /(\\s)/";
498 check_taint_not $`, "\t\$`";
499 check_taint_not $', "\t\$'";
500 check_taint_not $+, "\t\$+";
501 check_taint_not $1, "\t\$1";
502 check_taint_not $2, "\t\$2";
504 /(.)/; # untaint $&, $`, $', $+, $1.
505 check_taint_not $&, "\$& from /(.)/";
508 check_taint_not $&, "\$& from /(\\S)/";
509 check_taint_not $`, "\t\$`";
510 check_taint_not $', "\t\$'";
511 check_taint_not $+, "\t\$+";
512 check_taint_not $1, "\t\$1";
513 check_taint_not $2, "\t\$2";
515 /(.)/; # untaint $&, $`, $', $+, $1.
516 check_taint_not $&, "\$& from /(.)/";
519 check_taint_not $&, "\$& from /(\\d)/";
520 check_taint_not $`, "\t\$`";
521 check_taint_not $', "\t\$'";
522 check_taint_not $+, "\t\$+";
523 check_taint_not $1, "\t\$1";
524 check_taint_not $2, "\t\$2";
526 /(.)/; # untaint $&, $`, $', $+, $1.
527 check_taint_not $&, "\$& from /(.)/";
530 check_taint_not $&, "\$& from /(\\D)/";
531 check_taint_not $`, "\t\$`";
532 check_taint_not $', "\t\$'";
533 check_taint_not $+, "\t\$+";
534 check_taint_not $1, "\t\$1";
535 check_taint_not $2, "\t\$2";
537 /(.)/; # untaint $&, $`, $', $+, $1.
538 check_taint_not $&, "\$& from /(.)/";
541 check_taint_not $&, "\$& from /([[:alnum:]])/";
542 check_taint_not $`, "\t\$`";
543 check_taint_not $', "\t\$'";
544 check_taint_not $+, "\t\$+";
545 check_taint_not $1, "\t\$1";
546 check_taint_not $2, "\t\$2";
548 /(.)/; # untaint $&, $`, $', $+, $1.
549 check_taint_not $&, "\$& from /(.)/";
552 check_taint_not $&, "\$& from /([[:^alnum:]])/";
553 check_taint_not $`, "\t\$`";
554 check_taint_not $', "\t\$'";
555 check_taint_not $+, "\t\$+";
556 check_taint_not $1, "\t\$1";
557 check_taint_not $2, "\t\$2";
560 check_taint_not $&, "\$& from /(a)|(\\w)/";
561 check_taint_not $`, "\t\$`";
562 check_taint_not $', "\t\$'";
563 check_taint_not $+, "\t\$+";
564 check_taint_not $1, "\t\$1";
565 ok($1 eq 'a', ("\t" x 5) . "\$1 is 'a'");
566 ok(! defined $2, ("\t" x 5) . "\$2 is undefined");
567 check_taint_not $2, "\t\$2";
568 check_taint_not $3, "\t\$3";
570 /(.)/; # untaint $&, $`, $', $+, $1.
571 check_taint_not $&, "\$& from /(.)/";
573 "\N{CYRILLIC SMALL LETTER A}" =~ /(\N{CYRILLIC CAPITAL LETTER A})/i;
574 check_taint_not $&, "\$& from /(\\N{CYRILLIC CAPITAL LETTER A})/i";
575 check_taint_not $`, "\t\$`";
576 check_taint_not $', "\t\$'";
577 check_taint_not $+, "\t\$+";
578 check_taint_not $1, "\t\$1";
579 ok($1 eq "\N{CYRILLIC SMALL LETTER A}", ("\t" x 4) . "\t\$1 is 'small cyrillic a'");
580 check_taint_not $2, "\t\$2";
582 /(.)/; # untaint $&, $`, $', $+, $1.
583 check_taint_not $&, "\$& from /./";
585 "(\N{KELVIN SIGN})" =~ /(\N{KELVIN SIGN})/i;
586 check_taint_not $&, "\$& from /(\\N{KELVIN SIGN})/i";
587 check_taint_not $`, "\t\$`";
588 check_taint_not $', "\t\$'";
589 check_taint_not $+, "\t\$+";
590 check_taint_not $1, "\t\$1";
591 check_taint_not $2, "\t\$2";
593 /(.)/; # untaint $&, $`, $', $+, $1.
594 check_taint_not $&, "\$& from /(.)/";
597 check_taint_not $&, "\$& from /(.)\\b(.)/";
598 check_taint_not $`, "\t\$`";
599 check_taint_not $', "\t\$'";
600 check_taint_not $+, "\t\$+";
601 check_taint_not $1, "\t\$1";
602 check_taint_not $2, "\t\$2";
603 check_taint_not $3, "\t\$3";
605 /(.)/; # untaint $&, $`, $', $+, $1.
606 check_taint_not $&, "\$& from /./";
609 check_taint_not $&, "\$& from /(.)\\B(.)/";
610 check_taint_not $`, "\t\$`";
611 check_taint_not $', "\t\$'";
612 check_taint_not $+, "\t\$+";
613 check_taint_not $1, "\t\$1";
614 check_taint_not $2, "\t\$2";
615 check_taint_not $3, "\t\$3";
617 /(.)/; # untaint $&, $`, $', $+, $1.
618 check_taint_not $&, "\$& from /./";
620 "aaa" =~ /(.).(\1)/i; # notaint because not locale dependent
621 check_taint_not $&, "\$ & from /(.).(\\1)/";
622 check_taint_not $`, "\t\$`";
623 check_taint_not $', "\t\$'";
624 check_taint_not $+, "\t\$+";
625 check_taint_not $1, "\t\$1";
626 check_taint_not $2, "\t\$2";
627 check_taint_not $3, "\t\$3";
629 /(.)/; # untaint $&, $`, $', $+, $1.
630 check_taint_not $&, "\$ & from /./";
632 $_ = $a; # untaint $_
634 check_taint_not $_, 'untainting $_ works';
637 check_taint_not $&, "\$ & from /(b)/";
638 check_taint_not $`, "\t\$`";
639 check_taint_not $', "\t\$'";
640 check_taint_not $+, "\t\$+";
641 check_taint_not $1, "\t\$1";
642 check_taint_not $2, "\t\$2";
644 $_ = $a; # untaint $_
646 check_taint_not $_, 'untainting $_ works';
649 check_taint_not $_, '$_ (wasn\'t tainted) from s/(.+)/b/';
650 check_taint_not $&, "\t\$&";
651 check_taint_not $`, "\t\$`";
652 check_taint_not $', "\t\$'";
653 check_taint_not $+, "\t\$+";
654 check_taint_not $1, "\t\$1";
655 check_taint_not $2, "\t\$2";
657 $b = $a; # untaint $b
659 ($b = $a) =~ s/\w/$&/;
660 check_taint_not $b, '$b from ($b = $a) =~ s/\w/$&/';
661 check_taint_not $a, '$a from ($b = $a) =~ s/\w/$&/';
663 $_ = $a; # untaint $_
666 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\l$1/,'; # this must taint
667 check_taint_not $&, "\t\$&";
668 check_taint_not $`, "\t\$`";
669 check_taint_not $', "\t\$'";
670 check_taint_not $+, "\t\$+";
671 check_taint_not $1, "\t\$1";
672 check_taint_not $2, "\t\$2";
674 $_ = $a; # untaint $_
677 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\L$1/,';
678 check_taint_not $&, "\t\$&";
679 check_taint_not $`, "\t\$`";
680 check_taint_not $', "\t\$'";
681 check_taint_not $+, "\t\$+";
682 check_taint_not $1, "\t\$1";
683 check_taint_not $2, "\t\$2";
685 $_ = $a; # untaint $_
688 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\u$1/';
689 check_taint_not $&, "\t\$&";
690 check_taint_not $`, "\t\$`";
691 check_taint_not $', "\t\$'";
692 check_taint_not $+, "\t\$+";
693 check_taint_not $1, "\t\$1";
694 check_taint_not $2, "\t\$2";
696 $_ = $a; # untaint $_
699 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\U$1/';
700 check_taint_not $&, "\t\$&";
701 check_taint_not $`, "\t\$`";
702 check_taint_not $', "\t\$'";
703 check_taint_not $+, "\t\$+";
704 check_taint_not $1, "\t\$1";
705 check_taint_not $2, "\t\$2";
707 # After all this tainting $a should be cool.
709 check_taint_not $a, '$a still not tainted';
712 check_taint_not $1, '"a" =~ /([a-z])/';
713 "foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
714 check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
718 # Here are in scope of 'use locale'
720 # I think we've seen quite enough of taint.
721 # Let us do some *real* locale work now,
722 # unless setlocale() is missing (i.e. minitest).
724 # The test number before our first setlocale()
725 my $final_without_setlocale = $test_num;
729 debug "Scanning for locales...\n";
731 require POSIX; import POSIX ':locale_h';
733 my @Locale = find_locales([ &POSIX::LC_CTYPE, &POSIX::LC_NUMERIC, &POSIX::LC_ALL ]);
741 print "1..$test_num\n";
746 setlocale(&POSIX::LC_ALL, "C");
752 my %Known_bad_locale; # Failed test for a locale known to be bad
754 my @Added_alpha; # Alphas that aren't in the C locale.
758 # This returns a display string denoting the input parameter @_, each
759 # entry of which is a single character in the range 0-255. The first part
760 # of the output is a string of the characters in @_ that are ASCII
761 # graphics, and hence unambiguously displayable. They are given by code
762 # point order. The second part is the remaining code points, the ordinals
763 # of which are each displayed as 2-digit hex. Blanks are inserted so as
764 # to keep anything from the first part looking like a 2-digit hex number.
767 my @chars = sort { ord $a <=> ord $b } @_;
771 push @chars, chr(258); # This sentinel simplifies the loop termination
773 foreach my $i (0 .. @chars - 1) {
774 my $char = $chars[$i];
778 # We avoid using [:posix:] classes, as these are being tested in this
779 # file. Each equivalence class below is for things that can appear in
780 # a range; those that can't be in a range have class -1. 0 for those
781 # which should be output in hex; and >0 for the other ranges
782 if ($char =~ /[A-Z]/) {
785 elsif ($char =~ /[a-z]/) {
788 elsif ($char =~ /[0-9]/) {
791 # Uncomment to get literal punctuation displayed instead of hex
792 #elsif ($char =~ /[[\]!"#\$\%&\'()*+,.\/:\\;<=>?\@\^_`{|}~-]/) {
793 # $class = -1; # Punct never appears in a range
796 $class = 0; # Output in hex
799 if (! defined $range_start) {
801 $output .= " " . $char;
804 $range_start = ord $char;
805 $start_class = $class;
807 } # A range ends if not consecutive, or the class-type changes
808 elsif (ord $char != ($range_end = ord($chars[$i-1])) + 1
809 || $class != $start_class)
812 # Here, the current character is not in the range. This means the
813 # previous character must have been. Output the range up through
815 my $range_length = $range_end - $range_start + 1;
816 if ($start_class > 0) {
817 $output .= " " . chr($range_start);
818 $output .= "-" . chr($range_end) if $range_length > 1;
821 $output .= sprintf(" %02X", $range_start);
822 $output .= sprintf("-%02X", $range_end) if $range_length > 1;
825 # Handle the new current character, as potentially beginning a new
839 # Displays the string unambiguously. ASCII printables are always output
840 # as-is, though perhaps separated by blanks from other characters. If
841 # entirely printable ASCII, just returns the string. Otherwise if valid
842 # UTF-8 it uses the character names for non-printable-ASCII. Otherwise it
843 # outputs hex for each non-ASCII-printable byte.
845 return $string if $string =~ / ^ [[:print:]]* $/xa;
848 my $prev_was_punct = 1; # Beginning is considered punct
849 if (utf8::valid($string) && utf8::is_utf8($string)) {
851 foreach my $char (split "", $string) {
853 # Keep punctuation adjacent to other characters; otherwise
854 # separate them with a blank
855 if ($char =~ /[[:punct:]]/a) {
859 elsif ($char =~ /[[:print:]]/a) {
860 $result .= " " unless $prev_was_punct;
865 $result .= " " unless $prev_was_punct;
866 my $name = charnames::viacode(ord $char);
867 $result .= (defined $name) ? $name : ':unknown:';
874 foreach my $char (split "", $string) {
875 if ($char =~ /[[:punct:]]/a) {
879 elsif ($char =~ /[[:print:]]/a) {
880 $result .= " " unless $prev_was_punct;
885 $result .= " " unless $prev_was_punct;
886 $result .= sprintf("%02X", ord $char);
896 my ($Locale, $i, $pass_fail, $message) = @_;
898 $message = " ($message)" if $message;
900 push @{$Okay{$i}}, $Locale;
903 $Known_bad_locale{$i}{$Locale} = 1 if exists $known_bad_locales{$^O}
904 && $Locale =~ $known_bad_locales{$^O};
905 $Problem{$i}{$Locale} = 1;
906 debug "failed $i ($test_names{$i}) with locale '$Locale'$message\n";
910 sub report_multi_result {
911 my ($Locale, $i, $results_ref) = @_;
913 # $results_ref points to an array, each element of which is a character that was
914 # in error for this test numbered '$i'. If empty, the test passed
918 $message = join " ", "for", disp_chars(@$results_ref);
920 report_result($Locale, $i, @$results_ref == 0, $message);
923 my $first_locales_test_number = $final_without_setlocale + 1;
924 my $locales_test_number;
925 my $not_necessarily_a_problem_test_number;
926 my $first_casing_test_number;
927 my %setlocale_failed; # List of locales that setlocale() didn't work on
929 foreach my $Locale (@Locale) {
930 $locales_test_number = $first_locales_test_number - 1;
932 debug "Locale = $Locale\n";
934 unless (setlocale(&POSIX::LC_ALL, $Locale)) {
935 $setlocale_failed{$Locale} = $Locale;
939 # We test UTF-8 locales only under ':not_characters'; It is easier to
940 # test them in other test files than here. Non- UTF-8 locales are tested
941 # only under plain 'use locale', as otherwise we would have to convert
942 # everything in them to Unicode.
944 my %UPPER = (); # All alpha X for which uc(X) == X and lc(X) != X
945 my %lower = (); # All alpha X for which lc(X) == X and uc(X) != X
946 my %BoThCaSe = (); # All alpha X for which uc(X) == lc(X) == X
948 my $is_utf8_locale = is_locale_utf8($Locale);
950 debug "is utf8 locale? = $is_utf8_locale\n";
952 debug "radix = " . disp_str(localeconv()->{decimal_point}) . "\n";
954 if (! $is_utf8_locale) {
956 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
957 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
958 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
959 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
960 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
961 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
962 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
963 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
964 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
965 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
966 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
967 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
968 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
969 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
970 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
972 # Sieve the uppercase and the lowercase.
974 for (@{$posixes{'word'}}) {
975 if (/[^\d_]/) { # skip digits and the _
986 use locale ':not_characters';
987 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
988 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
989 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
990 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
991 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
992 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
993 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
994 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
995 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
996 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
997 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
998 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
999 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
1000 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
1001 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
1002 for (@{$posixes{'word'}}) {
1003 if (/[^\d_]/) { # skip digits and the _
1014 # Ordered, where possible, in groups of "this is a subset of the next
1016 debug ":upper: = ", disp_chars(@{$posixes{'upper'}}), "\n";
1017 debug ":lower: = ", disp_chars(@{$posixes{'lower'}}), "\n";
1018 debug ":cased: = ", disp_chars(@{$posixes{'cased'}}), "\n";
1019 debug ":alpha: = ", disp_chars(@{$posixes{'alpha'}}), "\n";
1020 debug ":alnum: = ", disp_chars(@{$posixes{'alnum'}}), "\n";
1021 debug " w = ", disp_chars(@{$posixes{'word'}}), "\n";
1022 debug ":graph: = ", disp_chars(@{$posixes{'graph'}}), "\n";
1023 debug ":print: = ", disp_chars(@{$posixes{'print'}}), "\n";
1024 debug " d = ", disp_chars(@{$posixes{'digit'}}), "\n";
1025 debug ":xdigit: = ", disp_chars(@{$posixes{'xdigit'}}), "\n";
1026 debug ":blank: = ", disp_chars(@{$posixes{'blank'}}), "\n";
1027 debug " s = ", disp_chars(@{$posixes{'space'}}), "\n";
1028 debug ":punct: = ", disp_chars(@{$posixes{'punct'}}), "\n";
1029 debug ":cntrl: = ", disp_chars(@{$posixes{'cntrl'}}), "\n";
1030 debug ":ascii: = ", disp_chars(@{$posixes{'ascii'}}), "\n";
1032 foreach (keys %UPPER) {
1034 $BoThCaSe{$_}++ if exists $lower{$_};
1036 foreach (keys %lower) {
1037 $BoThCaSe{$_}++ if exists $UPPER{$_};
1039 foreach (keys %BoThCaSe) {
1045 foreach my $ord ( 0 .. 255 ) {
1046 $Unassigned{chr $ord} = 1;
1048 foreach my $class (keys %posixes) {
1049 foreach my $char (@{$posixes{$class}}) {
1050 delete $Unassigned{$char};
1054 debug "UPPER = ", disp_chars(sort { ord $a <=> ord $b } keys %UPPER), "\n";
1055 debug "lower = ", disp_chars(sort { ord $a <=> ord $b } keys %lower), "\n";
1056 debug "BoThCaSe = ", disp_chars(sort { ord $a <=> ord $b } keys %BoThCaSe), "\n";
1057 debug "Unassigned = ", disp_chars(sort { ord $a <=> ord $b } keys %Unassigned), "\n";
1061 foreach my $x (sort { ord $a <=> ord $b } keys %UPPER) {
1064 if ($is_utf8_locale) {
1065 use locale ':not_characters';
1066 $ok = $x =~ /[[:upper:]]/;
1067 $fold_ok = $x =~ /[[:lower:]]/i;
1071 $ok = $x =~ /[[:upper:]]/;
1072 $fold_ok = $x =~ /[[:lower:]]/i;
1074 push @failures, $x unless $ok;
1075 push @fold_failures, $x unless $fold_ok;
1077 $locales_test_number++;
1078 $first_casing_test_number = $locales_test_number;
1079 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/ matches all alpha X for which uc(X) == X and lc(X) != X';
1080 report_multi_result($Locale, $locales_test_number, \@failures);
1082 $locales_test_number++;
1084 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i matches all alpha X for which uc(X) == X and lc(X) != X';
1085 report_multi_result($Locale, $locales_test_number, \@fold_failures);
1088 undef @fold_failures;
1090 foreach my $x (sort { ord $a <=> ord $b } keys %lower) {
1093 if ($is_utf8_locale) {
1094 use locale ':not_characters';
1095 $ok = $x =~ /[[:lower:]]/;
1096 $fold_ok = $x =~ /[[:upper:]]/i;
1100 $ok = $x =~ /[[:lower:]]/;
1101 $fold_ok = $x =~ /[[:upper:]]/i;
1103 push @failures, $x unless $ok;
1104 push @fold_failures, $x unless $fold_ok;
1107 $locales_test_number++;
1108 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/ matches all alpha X for which lc(X) == X and uc(X) != X';
1109 report_multi_result($Locale, $locales_test_number, \@failures);
1111 $locales_test_number++;
1112 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/i matches all alpha X for which lc(X) == X and uc(X) != X';
1113 report_multi_result($Locale, $locales_test_number, \@fold_failures);
1115 { # Find the alphabetic characters that are not considered alphabetics
1116 # in the default (C) locale.
1121 for (keys %UPPER, keys %lower, keys %BoThCaSe) {
1122 push(@Added_alpha, $_) if (/\W/);
1126 @Added_alpha = sort { ord $a <=> ord $b } @Added_alpha;
1128 debug "Added_alpha = ", disp_chars(@Added_alpha), "\n";
1130 # Cross-check the whole 8-bit character set.
1132 ++$locales_test_number;
1134 $test_names{$locales_test_number} = 'Verify that \w and [:word:] are identical';
1135 for (map { chr } 0..255) {
1136 if ($is_utf8_locale) {
1137 use locale ':not_characters';
1138 push @f, $_ unless /[[:word:]]/ == /\w/;
1141 push @f, $_ unless /[[:word:]]/ == /\w/;
1144 report_multi_result($Locale, $locales_test_number, \@f);
1146 ++$locales_test_number;
1148 $test_names{$locales_test_number} = 'Verify that \d and [:digit:] are identical';
1149 for (map { chr } 0..255) {
1150 if ($is_utf8_locale) {
1151 use locale ':not_characters';
1152 push @f, $_ unless /[[:digit:]]/ == /\d/;
1155 push @f, $_ unless /[[:digit:]]/ == /\d/;
1158 report_multi_result($Locale, $locales_test_number, \@f);
1160 ++$locales_test_number;
1162 $test_names{$locales_test_number} = 'Verify that \s and [:space:] are identical';
1163 for (map { chr } 0..255) {
1164 if ($is_utf8_locale) {
1165 use locale ':not_characters';
1166 push @f, $_ unless /[[:space:]]/ == /\s/;
1169 push @f, $_ unless /[[:space:]]/ == /\s/;
1172 report_multi_result($Locale, $locales_test_number, \@f);
1174 ++$locales_test_number;
1176 $test_names{$locales_test_number} = 'Verify that [:posix:] and [:^posix:] are mutually exclusive';
1177 for (map { chr } 0..255) {
1178 if ($is_utf8_locale) {
1179 use locale ':not_characters';
1180 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
1181 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
1182 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
1183 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
1184 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
1185 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
1186 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
1187 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
1188 (/[[:print:]]/ xor /[[:^print:]]/) ||
1189 (/[[:space:]]/ xor /[[:^space:]]/) ||
1190 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
1191 (/[[:word:]]/ xor /[[:^word:]]/) ||
1192 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1194 # effectively is what [:cased:] would be if it existed.
1195 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1198 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
1199 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
1200 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
1201 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
1202 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
1203 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
1204 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
1205 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
1206 (/[[:print:]]/ xor /[[:^print:]]/) ||
1207 (/[[:space:]]/ xor /[[:^space:]]/) ||
1208 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
1209 (/[[:word:]]/ xor /[[:^word:]]/) ||
1210 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1211 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1214 report_multi_result($Locale, $locales_test_number, \@f);
1216 # The rules for the relationships are given in:
1217 # http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html
1220 ++$locales_test_number;
1222 $test_names{$locales_test_number} = 'Verify that [:lower:] contains at least a-z';
1224 if ($is_utf8_locale) {
1225 use locale ':not_characters';
1226 push @f, $_ unless /[[:lower:]]/;
1229 push @f, $_ unless /[[:lower:]]/;
1232 report_multi_result($Locale, $locales_test_number, \@f);
1234 ++$locales_test_number;
1236 $test_names{$locales_test_number} = 'Verify that [:lower:] is a subset of [:alpha:]';
1237 for (map { chr } 0..255) {
1238 if ($is_utf8_locale) {
1239 use locale ':not_characters';
1240 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1243 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1246 report_multi_result($Locale, $locales_test_number, \@f);
1248 ++$locales_test_number;
1250 $test_names{$locales_test_number} = 'Verify that [:upper:] contains at least A-Z';
1252 if ($is_utf8_locale) {
1253 use locale ':not_characters';
1254 push @f, $_ unless /[[:upper:]]/;
1257 push @f, $_ unless /[[:upper:]]/;
1260 report_multi_result($Locale, $locales_test_number, \@f);
1262 ++$locales_test_number;
1264 $test_names{$locales_test_number} = 'Verify that [:upper:] is a subset of [:alpha:]';
1265 for (map { chr } 0..255) {
1266 if ($is_utf8_locale) {
1267 use locale ':not_characters';
1268 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1271 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1274 report_multi_result($Locale, $locales_test_number, \@f);
1276 ++$locales_test_number;
1278 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i is a subset of [:alpha:]';
1279 for (map { chr } 0..255) {
1280 if ($is_utf8_locale) {
1281 use locale ':not_characters';
1282 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1285 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1288 report_multi_result($Locale, $locales_test_number, \@f);
1290 ++$locales_test_number;
1292 $test_names{$locales_test_number} = 'Verify that [:alpha:] is a subset of [:alnum:]';
1293 for (map { chr } 0..255) {
1294 if ($is_utf8_locale) {
1295 use locale ':not_characters';
1296 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1299 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1302 report_multi_result($Locale, $locales_test_number, \@f);
1304 ++$locales_test_number;
1306 $test_names{$locales_test_number} = 'Verify that [:digit:] contains at least 0-9';
1308 if ($is_utf8_locale) {
1309 use locale ':not_characters';
1310 push @f, $_ unless /[[:digit:]]/;
1313 push @f, $_ unless /[[:digit:]]/;
1316 report_multi_result($Locale, $locales_test_number, \@f);
1318 ++$locales_test_number;
1320 $test_names{$locales_test_number} = 'Verify that [:digit:] is a subset of [:alnum:]';
1321 for (map { chr } 0..255) {
1322 if ($is_utf8_locale) {
1323 use locale ':not_characters';
1324 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1327 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1330 report_multi_result($Locale, $locales_test_number, \@f);
1332 ++$locales_test_number;
1334 $test_names{$locales_test_number} = 'Verify that [:digit:] matches either 10 or 20 code points';
1335 report_result($Locale, $locales_test_number, @{$posixes{'digit'}} == 10 || @{$posixes{'digit'}} == 20);
1337 ++$locales_test_number;
1339 $test_names{$locales_test_number} = 'Verify that if there is a second set of digits in [:digit:], they are consecutive';
1340 if (@{$posixes{'digit'}} == 20) {
1342 for (map { chr } 0..255) {
1343 next unless /[[:digit:]]/;
1345 if (defined $previous_ord) {
1346 if ($is_utf8_locale) {
1347 use locale ':not_characters';
1348 push @f, $_ if ord $_ != $previous_ord + 1;
1351 push @f, $_ if ord $_ != $previous_ord + 1;
1354 $previous_ord = ord $_;
1357 report_multi_result($Locale, $locales_test_number, \@f);
1359 ++$locales_test_number;
1361 my @xdigit_digits; # :digit: & :xdigit:
1362 $test_names{$locales_test_number} = 'Verify that [:xdigit:] contains one or two blocks of 10 consecutive [:digit:] chars';
1363 for (map { chr } 0..255) {
1364 if ($is_utf8_locale) {
1365 use locale ':not_characters';
1366 # For utf8 locales, we actually use a stricter test: that :digit:
1367 # is a subset of :xdigit:, as we know that only 0-9 should match
1368 push @f, $_ if /[[:digit:]]/ and ! /[[:xdigit:]]/;
1371 push @xdigit_digits, $_ if /[[:digit:]]/ and /[[:xdigit:]]/;
1374 if (! $is_utf8_locale) {
1376 # For non-utf8 locales, @xdigit_digits is a list of the characters
1377 # that are both :xdigit: and :digit:. Because :digit: is stored in
1378 # increasing code point order (unless the tests above failed),
1379 # @xdigit_digits is as well. There should be exactly 10 or
1381 if (@xdigit_digits != 10 && @xdigit_digits != 20) {
1382 @f = @xdigit_digits;
1386 # Look for contiguity in the series, adding any wrong ones to @f
1387 my @temp = @xdigit_digits;
1389 push @f, $temp[1] if ($temp[0] != $temp[1] - 1)
1391 # Skip this test for the 0th character of
1392 # the second block of 10, as it won't be
1393 # contiguous with the previous block
1394 && (! defined $xdigit_digits[10]
1395 || $temp[1] != $xdigit_digits[10]);
1401 report_multi_result($Locale, $locales_test_number, \@f);
1403 ++$locales_test_number;
1405 $test_names{$locales_test_number} = 'Verify that [:xdigit:] contains at least A-F, a-f';
1406 for ('A' .. 'F', 'a' .. 'f') {
1407 if ($is_utf8_locale) {
1408 use locale ':not_characters';
1409 push @f, $_ unless /[[:xdigit:]]/;
1412 push @f, $_ unless /[[:xdigit:]]/;
1415 report_multi_result($Locale, $locales_test_number, \@f);
1417 ++$locales_test_number;
1419 $test_names{$locales_test_number} = 'Verify that any additional members of [:xdigit:], are in groups of 6 consecutive code points';
1422 for my $chr (map { chr } 0..255) {
1423 next unless $chr =~ /[[:xdigit:]]/;
1424 if ($is_utf8_locale) {
1425 next if $chr =~ /[[:digit:]]/;
1428 next if grep { $chr eq $_ } @xdigit_digits;
1430 next if $chr =~ /[A-Fa-f]/;
1431 if (defined $previous_ord) {
1432 if ($is_utf8_locale) {
1433 use locale ':not_characters';
1434 push @f, $chr if ord $chr != $previous_ord + 1;
1437 push @f, $chr if ord $chr != $previous_ord + 1;
1442 undef $previous_ord;
1445 $previous_ord = ord $chr;
1448 report_multi_result($Locale, $locales_test_number, \@f);
1450 ++$locales_test_number;
1452 $test_names{$locales_test_number} = 'Verify that [:xdigit:] is a subset of [:graph:]';
1453 for (map { chr } 0..255) {
1454 if ($is_utf8_locale) {
1455 use locale ':not_characters';
1456 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1459 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1462 report_multi_result($Locale, $locales_test_number, \@f);
1464 # Note that xdigit doesn't have to be a subset of alnum
1466 ++$locales_test_number;
1468 $test_names{$locales_test_number} = 'Verify that [:punct:] is a subset of [:graph:]';
1469 for (map { chr } 0..255) {
1470 if ($is_utf8_locale) {
1471 use locale ':not_characters';
1472 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1475 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1478 report_multi_result($Locale, $locales_test_number, \@f);
1480 ++$locales_test_number;
1482 $test_names{$locales_test_number} = 'Verify that the space character is not in [:graph:]';
1483 if ($is_utf8_locale) {
1484 use locale ':not_characters';
1485 push @f, " " if " " =~ /[[:graph:]]/;
1488 push @f, " " if " " =~ /[[:graph:]]/;
1490 report_multi_result($Locale, $locales_test_number, \@f);
1492 ++$locales_test_number;
1494 $test_names{$locales_test_number} = 'Verify that [:space:] contains at least [\f\n\r\t\cK ]';
1495 for (' ', "\f", "\n", "\r", "\t", "\cK") {
1496 if ($is_utf8_locale) {
1497 use locale ':not_characters';
1498 push @f, $_ unless /[[:space:]]/;
1501 push @f, $_ unless /[[:space:]]/;
1504 report_multi_result($Locale, $locales_test_number, \@f);
1506 ++$locales_test_number;
1508 $test_names{$locales_test_number} = 'Verify that [:blank:] contains at least [\t ]';
1510 if ($is_utf8_locale) {
1511 use locale ':not_characters';
1512 push @f, $_ unless /[[:blank:]]/;
1515 push @f, $_ unless /[[:blank:]]/;
1518 report_multi_result($Locale, $locales_test_number, \@f);
1520 ++$locales_test_number;
1522 $test_names{$locales_test_number} = 'Verify that [:blank:] is a subset of [:space:]';
1523 for (map { chr } 0..255) {
1524 if ($is_utf8_locale) {
1525 use locale ':not_characters';
1526 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1529 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1532 report_multi_result($Locale, $locales_test_number, \@f);
1534 ++$locales_test_number;
1536 $test_names{$locales_test_number} = 'Verify that [:graph:] is a subset of [:print:]';
1537 for (map { chr } 0..255) {
1538 if ($is_utf8_locale) {
1539 use locale ':not_characters';
1540 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1543 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1546 report_multi_result($Locale, $locales_test_number, \@f);
1548 ++$locales_test_number;
1550 $test_names{$locales_test_number} = 'Verify that the space character is in [:print:]';
1551 if ($is_utf8_locale) {
1552 use locale ':not_characters';
1553 push @f, " " if " " !~ /[[:print:]]/;
1556 push @f, " " if " " !~ /[[:print:]]/;
1558 report_multi_result($Locale, $locales_test_number, \@f);
1560 ++$locales_test_number;
1562 $test_names{$locales_test_number} = 'Verify that isn\'t both [:cntrl:] and [:print:]';
1563 for (map { chr } 0..255) {
1564 if ($is_utf8_locale) {
1565 use locale ':not_characters';
1566 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1569 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1572 report_multi_result($Locale, $locales_test_number, \@f);
1574 ++$locales_test_number;
1576 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alpha:] and [:digit:]';
1577 for (map { chr } 0..255) {
1578 if ($is_utf8_locale) {
1579 use locale ':not_characters';
1580 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1583 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1586 report_multi_result($Locale, $locales_test_number, \@f);
1588 ++$locales_test_number;
1590 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alnum:] and [:punct:]';
1591 for (map { chr } 0..255) {
1592 if ($is_utf8_locale) {
1593 use locale ':not_characters';
1594 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1597 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1600 report_multi_result($Locale, $locales_test_number, \@f);
1602 ++$locales_test_number;
1604 $test_names{$locales_test_number} = 'Verify that isn\'t both [:xdigit:] and [:punct:]';
1605 for (map { chr } 0..255) {
1606 if ($is_utf8_locale) {
1607 use locale ':not_characters';
1608 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1611 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1614 report_multi_result($Locale, $locales_test_number, \@f);
1616 ++$locales_test_number;
1618 $test_names{$locales_test_number} = 'Verify that isn\'t both [:graph:] and [:space:]';
1619 for (map { chr } 0..255) {
1620 if ($is_utf8_locale) {
1621 use locale ':not_characters';
1622 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1625 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1628 report_multi_result($Locale, $locales_test_number, \@f);
1630 foreach ($first_casing_test_number..$locales_test_number) {
1631 $problematical_tests{$_} = 1;
1635 # Test for read-only scalars' locale vs non-locale comparisons.
1641 if ($is_utf8_locale) {
1642 use locale ':not_characters';
1643 $ok = ($a cmp "qwerty") == 0;
1647 $ok = ($a cmp "qwerty") == 0;
1649 report_result($Locale, ++$locales_test_number, $ok);
1650 $test_names{$locales_test_number} = 'Verify that cmp works with a read-only scalar; no- vs locale';
1654 my ($from, $to, $lesser, $greater,
1655 @test, %test, $test, $yes, $no, $sign);
1657 ++$locales_test_number;
1658 $test_names{$locales_test_number} = 'Verify that "le", "ne", etc work';
1659 $not_necessarily_a_problem_test_number = $locales_test_number;
1662 $from = int(($_*@{$posixes{'word'}})/10);
1663 $to = $from + int(@{$posixes{'word'}}/10);
1664 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1665 $lesser = join('', @{$posixes{'word'}}[$from..$to]);
1666 # Select a slice one character on.
1668 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1669 $greater = join('', @{$posixes{'word'}}[$from..$to]);
1670 if ($is_utf8_locale) {
1671 use locale ':not_characters';
1672 ($yes, $no, $sign) = ($lesser lt $greater
1674 : ("not ", " ", -1));
1678 ($yes, $no, $sign) = ($lesser lt $greater
1680 : ("not ", " ", -1));
1682 # all these tests should FAIL (return 0). Exact lt or gt cannot
1683 # be tested because in some locales, say, eacute and E may test
1687 $no.' ($lesser le $greater)', # 1
1688 'not ($lesser ne $greater)', # 2
1689 ' ($lesser eq $greater)', # 3
1690 $yes.' ($lesser ge $greater)', # 4
1691 $yes.' ($lesser ge $greater)', # 5
1692 $yes.' ($greater le $lesser )', # 7
1693 'not ($greater ne $lesser )', # 8
1694 ' ($greater eq $lesser )', # 9
1695 $no.' ($greater ge $lesser )', # 10
1696 'not (($lesser cmp $greater) == -($sign))' # 11
1698 @test{@test} = 0 x @test;
1700 for my $ti (@test) {
1701 if ($is_utf8_locale) {
1702 use locale ':not_characters';
1703 $test{$ti} = eval $ti;
1706 # Already in 'use locale';
1707 $test{$ti} = eval $ti;
1709 $test ||= $test{$ti}
1711 report_result($Locale, $locales_test_number, $test == 0);
1713 debug "lesser = '$lesser'\n";
1714 debug "greater = '$greater'\n";
1715 debug "lesser cmp greater = ",
1716 $lesser cmp $greater, "\n";
1717 debug "greater cmp lesser = ",
1718 $greater cmp $lesser, "\n";
1719 debug "(greater) from = $from, to = $to\n";
1720 for my $ti (@test) {
1721 debugf("# %-40s %-4s", $ti,
1722 $test{$ti} ? 'FAIL' : 'ok');
1723 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
1724 debugf("(%s == %4d)", $1, eval $1);
1766 if (! $is_utf8_locale) {
1769 my ($x, $y) = (1.23, 1.23);
1772 printf ''; # printf used to reset locale to "C"
1777 my $z = sprintf ''; # sprintf used to reset locale to "C"
1784 local $SIG{__WARN__} =
1790 # The == (among other ops) used to warn for locales
1791 # that had something else than "." as the radix character.
1815 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1817 $ok14 = $ok14_5 = $ok15 = $ok16 = 1; # Skip for non-utf8 locales
1821 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1823 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1826 use locale ':not_characters';
1828 my ($x, $y) = (1.23, 1.23);
1830 printf ''; # printf used to reset locale to "C"
1835 my $z = sprintf ''; # sprintf used to reset locale to "C"
1841 local $SIG{__WARN__} =
1867 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1870 # Look for non-ASCII error messages, and verify that the first
1871 # such is in UTF-8 (the others almost certainly will be like the
1872 # first). This is only done if the current locale has LC_MESSAGES
1875 if ( locales_enabled('LC_MESSAGES')
1876 && setlocale(&POSIX::LC_MESSAGES, $Locale))
1878 foreach my $err (keys %!) {
1880 $! = eval "&Errno::$err"; # Convert to strerror() output
1881 my $strerror = "$!";
1882 if ("$strerror" =~ /\P{ASCII}/) {
1883 $ok14 = utf8::is_utf8($strerror);
1885 $ok14_5 = "$!" !~ /\P{ASCII}/;
1891 # Similarly, we verify that a non-ASCII radix is in UTF-8. This
1892 # also catches if there is a disparity between sprintf and
1895 my $string_g = "$g";
1896 my $sprintf_g = sprintf("%g", $g);
1898 $ok15 = $string_g =~ / ^ \p{ASCII}+ $ /x || utf8::is_utf8($string_g);
1899 $ok16 = $sprintf_g eq $string_g;
1903 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1905 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1909 if (setlocale(&POSIX::LC_TIME, $Locale)) { # These tests aren't affected by
1911 my @times = CORE::localtime();
1914 $ok19 = POSIX::strftime("%p", @times) ne "%p"; # [perl #119425]
1915 my $date = POSIX::strftime("'%A' '%B' '%Z' '%p'", @times);
1916 debug("'Day' 'Month' 'TZ' 'am/pm' = ", disp_str($date));
1918 # If there is any non-ascii, it better be UTF-8 in a UTF-8 locale, and
1919 # not UTF-8 if the locale isn't UTF-8.
1920 $ok20 = $date =~ / ^ \p{ASCII}+ $ /x
1921 || $is_utf8_locale == utf8::is_utf8($date);
1925 if (locales_enabled('LC_MESSAGES')) {
1926 foreach my $err (keys %!) {
1929 $! = eval "&Errno::$err"; # Convert to strerror() output
1930 my $strerror = "$!";
1931 if ("$strerror" =~ /\P{ASCII}/) {
1938 report_result($Locale, ++$locales_test_number, $ok1);
1939 $test_names{$locales_test_number} = 'Verify that an intervening printf doesn\'t change assignment results';
1940 my $first_a_test = $locales_test_number;
1942 debug "$first_a_test..$locales_test_number: \$a = $a, \$b = $b, Locale = $Locale\n";
1944 report_result($Locale, ++$locales_test_number, $ok2);
1945 $test_names{$locales_test_number} = 'Verify that an intervening sprintf doesn\'t change assignment results';
1947 my $first_c_test = $locales_test_number;
1949 $test_names{++$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a constant';
1950 if ($Config{usequadmath}) {
1951 print "# Skip: no locale radix with usequadmath ($test_names{$locales_test_number})\n";
1952 report_result($Locale, $locales_test_number, 1);
1954 report_result($Locale, $locales_test_number, $ok3);
1955 $problematical_tests{$locales_test_number} = 1;
1958 $test_names{++$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar';
1959 if ($Config{usequadmath}) {
1960 print "# Skip: no locale radix with usequadmath ($test_names{$locales_test_number})\n";
1961 report_result($Locale, $locales_test_number, 1);
1963 report_result($Locale, $locales_test_number, $ok4);
1964 $problematical_tests{$locales_test_number} = 1;
1967 report_result($Locale, ++$locales_test_number, $ok5);
1968 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar and an intervening sprintf';
1969 $problematical_tests{$locales_test_number} = 1;
1971 debug "$first_c_test..$locales_test_number: \$c = $c, \$d = $d, Locale = $Locale\n";
1973 report_result($Locale, ++$locales_test_number, $ok6);
1974 $test_names{$locales_test_number} = 'Verify that can assign stringified under inner no-locale block';
1975 my $first_e_test = $locales_test_number;
1977 report_result($Locale, ++$locales_test_number, $ok7);
1978 $test_names{$locales_test_number} = 'Verify that "==" with a scalar still works in inner no locale';
1980 $test_names{++$locales_test_number} = 'Verify that "==" with a scalar and an intervening sprintf still works in inner no locale';
1981 if ($Config{usequadmath}) {
1982 print "# Skip: no locale radix with usequadmath ($test_names{$locales_test_number})\n";
1983 report_result($Locale, $locales_test_number, 1);
1985 report_result($Locale, $locales_test_number, $ok8);
1986 $problematical_tests{$locales_test_number} = 1;
1989 debug "$first_e_test..$locales_test_number: \$e = $e, no locale\n";
1991 report_result($Locale, ++$locales_test_number, $ok9);
1992 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a constant';
1993 $problematical_tests{$locales_test_number} = 1;
1994 my $first_f_test = $locales_test_number;
1996 report_result($Locale, ++$locales_test_number, $ok10);
1997 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar';
1998 $problematical_tests{$locales_test_number} = 1;
2000 $test_names{++$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar and an intervening sprintf';
2001 if ($Config{usequadmath}) {
2002 print "# Skip: no locale radix with usequadmath ($test_names{$locales_test_number})\n";
2003 report_result($Locale, $locales_test_number, 1);
2005 report_result($Locale, $locales_test_number, $ok11);
2006 $problematical_tests{$locales_test_number} = 1;
2009 report_result($Locale, ++$locales_test_number, $ok12);
2010 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix can participate in an addition and function call as numeric';
2011 $problematical_tests{$locales_test_number} = 1;
2013 report_result($Locale, ++$locales_test_number, $ok13);
2014 $test_names{$locales_test_number} = 'Verify that don\'t get warning under "==" even if radix is not a dot';
2015 $problematical_tests{$locales_test_number} = 1;
2017 report_result($Locale, ++$locales_test_number, $ok14);
2018 $test_names{$locales_test_number} = 'Verify that non-ASCII UTF-8 error messages are in UTF-8';
2020 report_result($Locale, ++$locales_test_number, $ok14_5);
2021 $test_names{$locales_test_number} = '... and are ASCII outside "use locale"';
2023 report_result($Locale, ++$locales_test_number, $ok15);
2024 $test_names{$locales_test_number} = 'Verify that a number with a UTF-8 radix has a UTF-8 stringification';
2026 report_result($Locale, ++$locales_test_number, $ok16);
2027 $test_names{$locales_test_number} = 'Verify that a sprintf of a number with a UTF-8 radix yields UTF-8';
2029 report_result($Locale, ++$locales_test_number, $ok17);
2030 $test_names{$locales_test_number} = 'Verify that a sprintf of a number outside locale scope uses a dot radix';
2032 report_result($Locale, ++$locales_test_number, $ok18);
2033 $test_names{$locales_test_number} = 'Verify that a sprintf of a number back within locale scope uses locale radix';
2035 report_result($Locale, ++$locales_test_number, $ok19);
2036 $test_names{$locales_test_number} = 'Verify that strftime doesn\'t return "%p" in locales where %p is empty';
2038 report_result($Locale, ++$locales_test_number, $ok20);
2039 $test_names{$locales_test_number} = 'Verify that strftime returns date with UTF-8 flag appropriately set';
2040 $problematical_tests{$locales_test_number} = 1; # This is broken in
2043 report_result($Locale, ++$locales_test_number, $ok21);
2044 $test_names{$locales_test_number} = '"$!" is ASCII only outside of locale scope';
2046 debug "$first_f_test..$locales_test_number: \$f = $f, \$g = $g, back to locale = $Locale\n";
2048 # Does taking lc separately differ from taking
2049 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
2050 # The bug was in the caching of the 'o'-magic.
2051 if (! $is_utf8_locale) {
2057 return $lc0 cmp $lc1;
2061 return lc($_[0]) cmp lc($_[1]);
2068 report_result($Locale, ++$locales_test_number,
2069 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
2070 lcA($x, $z) == 0 && lcB($x, $z) == 0);
2073 use locale ':not_characters';
2078 return $lc0 cmp $lc1;
2082 return lc($_[0]) cmp lc($_[1]);
2089 report_result($Locale, ++$locales_test_number,
2090 lcC($x, $y) == 1 && lcD($x, $y) == 1 ||
2091 lcC($x, $z) == 0 && lcD($x, $z) == 0);
2093 $test_names{$locales_test_number} = 'Verify "lc(foo) cmp lc(bar)" is the same as using intermediaries for the cmp';
2095 # Does lc of an UPPER (if different from the UPPER) match
2096 # case-insensitively the UPPER, and does the UPPER match
2097 # case-insensitively the lc of the UPPER. And vice versa.
2101 my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
2104 ++$locales_test_number;
2105 $test_names{$locales_test_number} = 'Verify case insensitive matching works';
2106 foreach my $x (sort { ord $a <=> ord $b } keys %UPPER) {
2107 if (! $is_utf8_locale) {
2109 next unless uc $y eq $x;
2110 debug_more( "UPPER=", disp_chars(($x)),
2111 "; lc=", disp_chars(($y)), "; ",
2112 "; fc=", disp_chars((fc $x)), "; ",
2113 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
2114 $x =~ /\Q$y/i ? 1 : 0,
2116 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
2117 $y =~ /\Q$x/i ? 1 : 0,
2120 # If $x and $y contain regular expression characters
2121 # AND THEY lowercase (/i) to regular expression characters,
2122 # regcomp() will be mightily confused. No, the \Q doesn't
2123 # help here (maybe regex engine internal lowercasing
2124 # is done after the \Q?) An example of this happening is
2125 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
2126 # the chr(173) (the "[") is the lowercase of the chr(235).
2128 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
2129 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
2130 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
2131 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
2132 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
2133 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
2135 # Similar things can happen even under (bastardised)
2136 # non-EBCDIC locales: in many European countries before the
2137 # advent of ISO 8859-x nationally customised versions of
2138 # ISO 646 were devised, reusing certain punctuation
2139 # characters for modified characters needed by the
2140 # country/language. For example, the "|" might have
2141 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
2143 if ($x =~ $re || $y =~ $re) {
2144 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
2147 push @f, $x unless $x =~ /\Q$y/i && $y =~ /\Q$x/i;
2149 # fc is not a locale concept, so Perl uses lc for it.
2150 push @f, $x unless lc $x eq fc $x;
2153 use locale ':not_characters';
2155 next unless uc $y eq $x;
2156 debug_more( "UPPER=", disp_chars(($x)),
2157 "; lc=", disp_chars(($y)), "; ",
2158 "; fc=", disp_chars((fc $x)), "; ",
2159 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
2160 $x =~ /\Q$y/i ? 1 : 0,
2162 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
2163 $y =~ /\Q$x/i ? 1 : 0,
2166 push @f, $x unless $x =~ /\Q$y/i && $y =~ /\Q$x/i;
2168 # The places where Unicode's lc is different from fc are
2169 # skipped here by virtue of the 'next unless uc...' line above
2170 push @f, $x unless lc $x eq fc $x;
2174 foreach my $x (sort { ord $a <=> ord $b } keys %lower) {
2175 if (! $is_utf8_locale) {
2177 next unless lc $y eq $x;
2178 debug_more( "lower=", disp_chars(($x)),
2179 "; uc=", disp_chars(($y)), "; ",
2180 "; fc=", disp_chars((fc $x)), "; ",
2181 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
2182 $x =~ /\Q$y/i ? 1 : 0,
2184 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
2185 $y =~ /\Q$x/i ? 1 : 0,
2187 if ($x =~ $re || $y =~ $re) { # See above.
2188 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
2191 push @f, $x unless $x =~ /\Q$y/i && $y =~ /\Q$x/i;
2193 push @f, $x unless lc $x eq fc $x;
2196 use locale ':not_characters';
2198 next unless lc $y eq $x;
2199 debug_more( "lower=", disp_chars(($x)),
2200 "; uc=", disp_chars(($y)), "; ",
2201 "; fc=", disp_chars((fc $x)), "; ",
2202 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
2203 $x =~ /\Q$y/i ? 1 : 0,
2205 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
2206 $y =~ /\Q$x/i ? 1 : 0,
2208 push @f, $x unless $x =~ /\Q$y/i && $y =~ /\Q$x/i;
2210 push @f, $x unless lc $x eq fc $x;
2213 report_multi_result($Locale, $locales_test_number, \@f);
2214 $problematical_tests{$locales_test_number} = 1;
2220 ++$locales_test_number;
2221 $test_names{$locales_test_number} = 'Verify atof with locale radix and negative exponent';
2222 $problematical_tests{$locales_test_number} = 1;
2224 my $radix = POSIX::localeconv()->{decimal_point};
2226 "3.14e+9", "3${radix}14e+9", "3.14e-9", "3${radix}14e-9",
2227 "-3.14e+9", "-3${radix}14e+9", "-3.14e-9", "-3${radix}14e-9",
2230 if (! $is_utf8_locale) {
2232 for my $num (@nums) {
2234 unless sprintf("%g", $num) =~ /3.+14/;
2238 use locale ':not_characters';
2239 for my $num (@nums) {
2241 unless sprintf("%g", $num) =~ /3.+14/;
2245 if ($Config{usequadmath}) {
2246 print "# Skip: no locale radix with usequadmath ($Locale)\n";
2247 report_result($Locale, $locales_test_number, 1);
2249 report_result($Locale, $locales_test_number, @f == 0);
2251 print "# failed $locales_test_number locale '$Locale' numbers @f\n"
2257 my $final_locales_test_number = $locales_test_number;
2259 # Recount the errors.
2262 foreach $test_num ($first_locales_test_number..$final_locales_test_number) {
2263 if (%setlocale_failed) {
2266 elsif ($Problem{$test_num}
2267 || ! defined $Okay{$test_num}
2268 || ! @{$Okay{$test_num}})
2270 if (defined $not_necessarily_a_problem_test_number
2271 && $test_num == $not_necessarily_a_problem_test_number)
2273 print "# The failure of test $not_necessarily_a_problem_test_number is not necessarily fatal.\n";
2274 print "# It usually indicates a problem in the environment,\n";
2275 print "# not in Perl itself.\n";
2278 # If there are any locales that pass this test, or are known-bad, it
2279 # may be that there are enough passes that we TODO the failure.
2280 if (($Okay{$test_num} || $Known_bad_locale{$test_num})
2281 && grep { $_ == $test_num } keys %problematical_tests)
2283 no warnings 'experimental::postderef';
2285 # Don't count the known-bad failures when calculating the
2286 # percentage that fail.
2287 my $known_failures = (exists $Known_bad_locale{$test_num})
2288 ? scalar(keys $Known_bad_locale{$test_num}->%*)
2290 my $adjusted_failures = scalar(keys $Problem{$test_num}->%*)
2293 # Specially handle failures where only known-bad locales fail.
2294 # This makes the diagnositics clearer.
2295 if ($adjusted_failures <= 0) {
2296 print "not ok $test_num $test_names{$test_num} # TODO fails only on ",
2297 "known bad locales: ",
2298 join " ", keys $Known_bad_locale{$test_num}->%*, "\n";
2302 # Round to nearest .1%
2303 my $percent_fail = (int(.5 + (1000 * $adjusted_failures
2304 / scalar(@Locale))))
2306 if ($percent_fail < $acceptable_failure_percentage) {
2308 $test_names{$test_num} .= 'TODO';
2309 print "# ", 100 - $percent_fail, "% of locales not known to be problematic on this platform\n";
2310 print "# pass the following test, so it is likely that the failures\n";
2311 print "# are errors in the locale definitions. The test is marked TODO, as the\n";
2312 print "# problem is not likely to be Perl's\n";
2316 print "# $percent_fail% of locales (",
2317 scalar(keys $Problem{$test_num}->%*),
2320 ") fail the above test (TODO cut-off is ",
2321 $acceptable_failure_percentage,
2327 print "# The code points that had this failure are given above. Look for lines\n";
2328 print "# that match 'failed $test_num'\n";
2331 print "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
2332 print "# Then look at that output for lines that match 'failed $test_num'\n";
2336 print "ok $test_num";
2337 if (defined $test_names{$test_num}) {
2338 # If TODO is in the test name, make it thus
2339 my $todo = $test_names{$test_num} =~ s/TODO\s*//;
2340 print " $test_names{$test_num}";
2341 print " # TODO" if $todo;
2346 $test_num = $final_locales_test_number;
2348 unless ( $^O =~ m!^(dragonfly|openbsd|bitrig|mirbsd)$! ) {
2352 local $SIG{__WARN__} = sub {
2353 $warned = $_[0] =~ /uninitialized/;
2355 my $z = "y" . setlocale(&POSIX::LC_ALL, "xyzzy");
2356 ok($warned, "variable set to setlocale(BAD LOCALE) is considered uninitialized");
2359 # Test that tainting and case changing works on utf8 strings. These tests are
2360 # placed last to avoid disturbing the hard-coded test numbers that existed at
2361 # the time these were added above this in this file.
2362 # This also tests that locale overrides unicode_strings in the same scope for
2364 setlocale(&POSIX::LC_ALL, "C");
2367 use feature 'unicode_strings';
2369 foreach my $function ("uc", "ucfirst", "lc", "lcfirst", "fc") {
2370 my @list; # List of code points to test for $function
2372 # Used to calculate the changed case for ASCII characters by using the
2373 # ord, instead of using one of the functions under test.
2374 my $ascii_case_change_delta;
2375 my $above_latin1_case_change_delta; # Same for the specific ords > 255
2378 # We test an ASCII character, which should change case;
2379 # a Latin1 character, which shouldn't change case under this C locale,
2380 # an above-Latin1 character that when the case is changed would cross
2381 # the 255/256 boundary, so doesn't change case
2382 # (the \x{149} is one of these, but changes into 2 characters, the
2383 # first one of which doesn't cross the boundary.
2384 # the final one in each list is an above-Latin1 character whose case
2385 # does change. The code below uses its position in its list as a
2386 # marker to indicate that it, unlike the other code points above
2387 # ASCII, has a successful case change
2389 # All casing operations under locale (but not :not_characters) should
2391 if ($function =~ /^u/) {
2393 chr(utf8::unicode_to_native(0xe0)),
2394 chr(utf8::unicode_to_native(0xff)),
2395 "\x{fb00}", "\x{149}", "\x{101}");
2396 $ascii_case_change_delta = ($is_ebcdic) ? +64 : -32;
2397 $above_latin1_case_change_delta = -1;
2401 chr(utf8::unicode_to_native(0xC0)),
2402 "\x{17F}", "\x{100}");
2403 $ascii_case_change_delta = ($is_ebcdic) ? -64 : +32;
2404 $above_latin1_case_change_delta = +1;
2406 foreach my $is_utf8_locale (0 .. 1) {
2407 foreach my $j (0 .. $#list) {
2408 my $char = $list[$j];
2410 for my $encoded_in_utf8 (0 .. 1) {
2413 if (! $is_utf8_locale) {
2414 no warnings 'locale';
2415 $should_be = ($j == $#list)
2416 ? chr(ord($char) + $above_latin1_case_change_delta)
2417 : (length $char == 0 || utf8::native_to_unicode(ord($char)) > 127)
2419 : chr(ord($char) + $ascii_case_change_delta);
2421 # This monstrosity is in order to avoid using an eval,
2422 # which might perturb the results
2423 $changed = ($function eq "uc")
2425 : ($function eq "ucfirst")
2427 : ($function eq "lc")
2429 : ($function eq "lcfirst")
2431 : ($function eq "fc")
2433 : die("Unexpected function \"$function\"");
2439 # For utf8-locales the case changing functions
2440 # should work just like they do outside of locale.
2441 # Can use eval here because not testing it when
2443 $should_be = eval "$function('$char')";
2444 die "Unexpected eval error $@ from 'eval \"$function('$char')\"'" if $@;
2447 use locale ':not_characters';
2448 $changed = ($function eq "uc")
2450 : ($function eq "ucfirst")
2452 : ($function eq "lc")
2454 : ($function eq "lcfirst")
2456 : ($function eq "fc")
2458 : die("Unexpected function \"$function\"");
2460 ok($changed eq $should_be,
2461 "$function(\"$char\") in C locale "
2462 . (($is_utf8_locale)
2463 ? "(use locale ':not_characters'"
2465 . (($encoded_in_utf8)
2466 ? "; encoded in utf8)"
2467 : "; not encoded in utf8)")
2468 . " should be \"$should_be\", got \"$changed\"");
2470 # Tainting shouldn't happen for use locale :not_character
2473 ? check_taint($changed)
2474 : check_taint_not($changed);
2476 # Use UTF-8 next time through the loop
2477 utf8::upgrade($char);
2484 # Give final advice.
2488 foreach ($first_locales_test_number..$final_locales_test_number) {
2490 my @f = sort keys %{ $Problem{$_} };
2492 # Don't list the failures caused by known-bad locales.
2493 if (exists $known_bad_locales{$^O}) {
2494 @f = grep { $_ !~ $known_bad_locales{$^O} } @f;
2497 my $f = join(" ", @f);
2498 $f =~ s/(.{50,60}) /$1\n#\t/g;
2501 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
2503 "# on your system may have errors because the locale test $_\n",
2504 "# \"$test_names{$_}\"\n",
2505 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
2509 # If your users are not using these locales you are safe for the moment,
2510 # but please report this failure first to perlbug\@perl.com using the
2511 # perlbug script (as described in the INSTALL file) so that the exact
2512 # details of the failures can be sorted out first and then your operating
2513 # system supplier can be alerted about these anomalies.
2520 # Tell which locales were okay and which were not.
2525 foreach my $l (@Locale) {
2527 if ($setlocale_failed{$l}) {
2532 ($first_locales_test_number..$final_locales_test_number)
2534 $p++ if $Problem{$t}{$l};
2537 push @s, $l if $p == 0;
2538 push @F, $l unless $p == 0;
2542 my $s = join(" ", @s);
2543 $s =~ s/(.{50,60}) /$1\n#\t/g;
2546 "# The following locales\n#\n",
2548 "# tested okay.\n#\n",
2550 print "# None of your locales were fully okay.\n";
2554 my $F = join(" ", @F);
2555 $F =~ s/(.{50,60}) /$1\n#\t/g;
2559 $details = "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
2561 elsif ($debug == 1) {
2562 $details = "# For even more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=2.\n";
2566 "# The following locales\n#\n",
2568 "# had problems.\n#\n",
2571 print "# None of your locales were broken.\n";
2575 if (exists $known_bad_locales{$^O} && ! %Known_bad_locale) {
2577 print "ok $test_num $^O no longer has known bad locales # TODO\n";
2580 print "1..$test_num\n";