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 binmode STDOUT, ':utf8';
11 binmode STDERR, ':utf8';
17 require Config; import Config;
18 if (!$Config{d_setlocale} || $Config{ccflags} =~ /\bD?NO_LOCALE\b/) {
22 require './loc_tools.pl';
29 # =1 adds debugging output; =2 increases the verbosity somewhat
30 my $debug = $ENV{PERL_DEBUG_FULL_TEST} // 0;
32 # Certain tests have been shown to be problematical for a few locales. Don't
33 # fail them unless at least this percentage of the tested locales fail.
34 # Some Windows machines are defective in every locale but the C, calling \t
35 # printable; superscripts to be digits, etc. See
36 # http://markmail.org/message/5jwam4xsx4amsdnv. Also on AIX machines, many
37 # locales call a no-break space a graphic.
38 # (There aren't 1000 locales currently in existence, so 99.9 works)
39 my $acceptable_failure_percentage = ($^O =~ / ^ ( MSWin32 | AIX ) $ /ix)
43 # The list of test numbers of the problematic tests.
44 my %problematical_tests;
49 my $dumper = Dumpvalue->new(
56 my($mess) = join "", @_;
58 print $dumper->stringify($mess,1), "\n";
62 return unless $debug > 1;
75 my ($result, $message) = @_;
76 $message = "" unless defined $message;
78 print 'not ' unless ($result);
79 print "ok " . ++$test_num;
84 # First we'll do a lot of taint checking for locales.
85 # This is the easiest to test, actually, as any locale,
86 # even the default locale will taint under 'use locale'.
88 sub is_tainted { # hello, camel two.
89 no warnings 'uninitialized' ;
92 not eval { $dummy = join("", @_), kill 0; 1 }
95 sub check_taint ($;$) {
96 my $message_tail = $_[1] // "";
98 # Extra blanks are so aligns with taint_not output
99 $message_tail = ": $message_tail" if $message_tail;
100 ok is_tainted($_[0]), "verify that is tainted$message_tail";
103 sub check_taint_not ($;$) {
104 my $message_tail = $_[1] // "";
105 $message_tail = ": $message_tail" if $message_tail;
106 ok((not is_tainted($_[0])), "verify that isn't tainted$message_tail");
109 "\tb\t" =~ /^m?(\s)(.*)\1$/;
110 check_taint_not $&, "not tainted outside 'use locale'";
113 use locale; # engage locale and therefore locale taint.
115 # BE SURE TO COPY ANYTHING YOU ADD to these tests to the block below for
118 check_taint_not $a, '$a';
120 check_taint uc($a), 'uc($a)';
121 check_taint "\U$a", '"\U$a"';
122 check_taint ucfirst($a), 'ucfirst($a)';
123 check_taint "\u$a", '"\u$a"';
124 check_taint lc($a), 'lc($a)';
125 check_taint fc($a), 'fc($a)';
126 check_taint "\L$a", '"\L$a"';
127 check_taint "\F$a", '"\F$a"';
128 check_taint lcfirst($a), 'lcfirst($a)';
129 check_taint "\l$a", '"\l$a"';
131 check_taint_not sprintf('%e', 123.456), "sprintf('%e', 123.456)";
132 check_taint_not sprintf('%f', 123.456), "sprintf('%f', 123.456)";
133 check_taint_not sprintf('%g', 123.456), "sprintf('%g', 123.456)";
134 check_taint_not sprintf('%d', 123.456), "sprintf('%d', 123.456)";
135 check_taint_not sprintf('%x', 123.456), "sprintf('%x', 123.456)";
137 $_ = $a; # untaint $_
139 $_ = uc($a); # taint $_
141 check_taint $_, '$_ = uc($a)';
143 /(\w)/; # taint $&, $`, $', $+, $1.
144 check_taint $&, "\$& from /(\\w)/";
145 check_taint $`, "\t\$`";
146 check_taint $', "\t\$'";
147 check_taint $+, "\t\$+";
148 check_taint $1, "\t\$1";
149 check_taint_not $2, "\t\$2";
151 /(.)/; # untaint $&, $`, $', $+, $1.
152 check_taint_not $&, "\$& from /(.)/";
153 check_taint_not $`, "\t\$`";
154 check_taint_not $', "\t\$'";
155 check_taint_not $+, "\t\$+";
156 check_taint_not $1, "\t\$1";
157 check_taint_not $2, "\t\$2";
159 /(\W)/; # taint $&, $`, $', $+, $1.
160 check_taint $&, "\$& from /(\\W)/";
161 check_taint $`, "\t\$`";
162 check_taint $', "\t\$'";
163 check_taint $+, "\t\$+";
164 check_taint $1, "\t\$1";
165 check_taint_not $2, "\t\$2";
167 /(.)/; # untaint $&, $`, $', $+, $1.
168 check_taint_not $&, "\$& from /(.)/";
169 check_taint_not $`, "\t\$`";
170 check_taint_not $', "\t\$'";
171 check_taint_not $+, "\t\$+";
172 check_taint_not $1, "\t\$1";
173 check_taint_not $2, "\t\$2";
175 /(\s)/; # taint $&, $`, $', $+, $1.
176 check_taint $&, "\$& from /(\\s)/";
177 check_taint $`, "\t\$`";
178 check_taint $', "\t\$'";
179 check_taint $+, "\t\$+";
180 check_taint $1, "\t\$1";
181 check_taint_not $2, "\t\$2";
183 /(.)/; # untaint $&, $`, $', $+, $1.
184 check_taint_not $&, "\$& from /(.)/";
186 /(\S)/; # taint $&, $`, $', $+, $1.
187 check_taint $&, "\$& from /(\\S)/";
188 check_taint $`, "\t\$`";
189 check_taint $', "\t\$'";
190 check_taint $+, "\t\$+";
191 check_taint $1, "\t\$1";
192 check_taint_not $2, "\t\$2";
194 /(.)/; # untaint $&, $`, $', $+, $1.
195 check_taint_not $&, "\$& from /(.)/";
197 "0" =~ /(\d)/; # taint $&, $`, $', $+, $1.
198 check_taint $&, "\$& from /(\\d)/";
199 check_taint $`, "\t\$`";
200 check_taint $', "\t\$'";
201 check_taint $+, "\t\$+";
202 check_taint $1, "\t\$1";
203 check_taint_not $2, "\t\$2";
205 /(.)/; # untaint $&, $`, $', $+, $1.
206 check_taint_not $&, "\$& from /(.)/";
208 /(\D)/; # taint $&, $`, $', $+, $1.
209 check_taint $&, "\$& from /(\\D)/";
210 check_taint $`, "\t\$`";
211 check_taint $', "\t\$'";
212 check_taint $+, "\t\$+";
213 check_taint $1, "\t\$1";
214 check_taint_not $2, "\t\$2";
216 /(.)/; # untaint $&, $`, $', $+, $1.
217 check_taint_not $&, "\$& from /(.)/";
219 /([[:alnum:]])/; # taint $&, $`, $', $+, $1.
220 check_taint $&, "\$& from /([[:alnum:]])/";
221 check_taint $`, "\t\$`";
222 check_taint $', "\t\$'";
223 check_taint $+, "\t\$+";
224 check_taint $1, "\t\$1";
225 check_taint_not $2, "\t\$2";
227 /(.)/; # untaint $&, $`, $', $+, $1.
228 check_taint_not $&, "\$& from /(.)/";
230 /([[:^alnum:]])/; # taint $&, $`, $', $+, $1.
231 check_taint $&, "\$& from /([[:^alnum:]])/";
232 check_taint $`, "\t\$`";
233 check_taint $', "\t\$'";
234 check_taint $+, "\t\$+";
235 check_taint $1, "\t\$1";
236 check_taint_not $2, "\t\$2";
238 "a" =~ /(a)|(\w)/; # taint $&, $`, $', $+, $1.
239 check_taint $&, "\$& from /(a)|(\\w)/";
240 check_taint $`, "\t\$`";
241 check_taint $', "\t\$'";
242 check_taint $+, "\t\$+";
243 check_taint $1, "\t\$1";
244 ok($1 eq 'a', ("\t" x 5) . "\$1 is 'a'");
245 ok(! defined $2, ("\t" x 5) . "\$2 is undefined");
246 check_taint_not $2, "\t\$2";
247 check_taint_not $3, "\t\$3";
249 /(.)/; # untaint $&, $`, $', $+, $1.
250 check_taint_not $&, "\$& from /(.)/";
252 "\N{CYRILLIC SMALL LETTER A}" =~ /(\N{CYRILLIC CAPITAL LETTER A})/i; # no tainting because no locale dependence
253 check_taint_not $&, "\$& from /(\\N{CYRILLIC CAPITAL LETTER A})/i";
254 check_taint_not $`, "\t\$`";
255 check_taint_not $', "\t\$'";
256 check_taint_not $+, "\t\$+";
257 check_taint_not $1, "\t\$1";
258 ok($1 eq "\N{CYRILLIC SMALL LETTER A}", ("\t" x 4) . "\t\$1 is 'small cyrillic a'");
259 check_taint_not $2, "\t\$2";
261 /(.)/; # untaint $&, $`, $', $+, $1.
262 check_taint_not $&, "\$& from /./";
264 "(\N{KELVIN SIGN})" =~ /(\N{KELVIN SIGN})/i; # taints because depends on locale
265 check_taint $&, "\$& from /(\\N{KELVIN SIGN})/i";
266 check_taint $`, "\t\$`";
267 check_taint $', "\t\$'";
268 check_taint $+, "\t\$+";
269 check_taint $1, "\t\$1";
270 check_taint_not $2, "\t\$2";
272 /(.)/; # untaint $&, $`, $', $+, $1.
273 check_taint_not $&, "\$& from /(.)/";
275 "a:" =~ /(.)\b(.)/; # taint $&, $`, $', $+, $1.
276 check_taint $&, "\$& from /(.)\\b(.)/";
277 check_taint $`, "\t\$`";
278 check_taint $', "\t\$'";
279 check_taint $+, "\t\$+";
280 check_taint $1, "\t\$1";
281 check_taint $2, "\t\$2";
282 check_taint_not $3, "\t\$3";
284 /(.)/; # untaint $&, $`, $', $+, $1.
285 check_taint_not $&, "\$& from /./";
287 "aa" =~ /(.)\B(.)/; # taint $&, $`, $', $+, $1.
288 check_taint $&, "\$& from /(.)\\B(.)/";
289 check_taint $`, "\t\$`";
290 check_taint $', "\t\$'";
291 check_taint $+, "\t\$+";
292 check_taint $1, "\t\$1";
293 check_taint $2, "\t\$2";
294 check_taint_not $3, "\t\$3";
296 /(.)/; # untaint $&, $`, $', $+, $1.
297 check_taint_not $&, "\$& from /./";
299 "aaa" =~ /(.).(\1)/i; # notaint because not locale dependent
300 check_taint_not $&, "\$ & from /(.).(\\1)/";
301 check_taint_not $`, "\t\$`";
302 check_taint_not $', "\t\$'";
303 check_taint_not $+, "\t\$+";
304 check_taint_not $1, "\t\$1";
305 check_taint_not $2, "\t\$2";
306 check_taint_not $3, "\t\$3";
308 /(.)/; # untaint $&, $`, $', $+, $1.
309 check_taint_not $&, "\$ & from /./";
311 $_ = $a; # untaint $_
313 check_taint_not $_, 'untainting $_ works';
315 /(b)/; # this must not taint
316 check_taint_not $&, "\$ & from /(b)/";
317 check_taint_not $`, "\t\$`";
318 check_taint_not $', "\t\$'";
319 check_taint_not $+, "\t\$+";
320 check_taint_not $1, "\t\$1";
321 check_taint_not $2, "\t\$2";
323 $_ = $a; # untaint $_
325 check_taint_not $_, 'untainting $_ works';
327 $b = uc($a); # taint $b
328 s/(.+)/$b/; # this must taint only the $_
330 check_taint $_, '$_ (wasn\'t tainted) from s/(.+)/$b/ where $b is tainted';
331 check_taint_not $&, "\t\$&";
332 check_taint_not $`, "\t\$`";
333 check_taint_not $', "\t\$'";
334 check_taint_not $+, "\t\$+";
335 check_taint_not $1, "\t\$1";
336 check_taint_not $2, "\t\$2";
338 $_ = $a; # untaint $_
340 s/(.+)/b/; # this must not taint
341 check_taint_not $_, '$_ (wasn\'t tainted) from s/(.+)/b/';
342 check_taint_not $&, "\t\$&";
343 check_taint_not $`, "\t\$`";
344 check_taint_not $', "\t\$'";
345 check_taint_not $+, "\t\$+";
346 check_taint_not $1, "\t\$1";
347 check_taint_not $2, "\t\$2";
349 $b = $a; # untaint $b
351 ($b = $a) =~ s/\w/$&/;
352 check_taint $b, '$b from ($b = $a) =~ s/\w/$&/'; # $b should be tainted.
353 check_taint_not $a, '$a from ($b = $a) =~ s/\w/$&/'; # $a should be not.
355 $_ = $a; # untaint $_
357 s/(\w)/\l$1/; # this must taint
358 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\l$1/,'; # this must taint
359 check_taint $&, "\t\$&";
360 check_taint $`, "\t\$`";
361 check_taint $', "\t\$'";
362 check_taint $+, "\t\$+";
363 check_taint $1, "\t\$1";
364 check_taint_not $2, "\t\$2";
366 $_ = $a; # untaint $_
368 s/(\w)/\L$1/; # this must taint
369 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\L$1/,';
370 check_taint $&, "\t\$&";
371 check_taint $`, "\t\$`";
372 check_taint $', "\t\$'";
373 check_taint $+, "\t\$+";
374 check_taint $1, "\t\$1";
375 check_taint_not $2, "\t\$2";
377 $_ = $a; # untaint $_
379 s/(\w)/\u$1/; # this must taint
380 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\u$1/';
381 check_taint $&, "\t\$&";
382 check_taint $`, "\t\$`";
383 check_taint $', "\t\$'";
384 check_taint $+, "\t\$+";
385 check_taint $1, "\t\$1";
386 check_taint_not $2, "\t\$2";
388 $_ = $a; # untaint $_
390 s/(\w)/\U$1/; # this must taint
391 check_taint $_, '$_ (wasn\'t tainted) from s/(\w)/\U$1/';
392 check_taint $&, "\t\$&";
393 check_taint $`, "\t\$`";
394 check_taint $', "\t\$'";
395 check_taint $+, "\t\$+";
396 check_taint $1, "\t\$1";
397 check_taint_not $2, "\t\$2";
399 # After all this tainting $a should be cool.
401 check_taint_not $a, '$a still not tainted';
404 check_taint_not $1, '"a" =~ /([a-z])/';
405 "foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
406 check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
408 # BE SURE TO COPY ANYTHING YOU ADD to the block below
410 { # This is just the previous tests copied here with a different
411 # compile-time pragma.
413 use locale ':not_characters'; # engage restricted locale with different
415 check_taint_not $a, '$a';
417 check_taint_not uc($a), 'uc($a)';
418 check_taint_not "\U$a", '"\U$a"';
419 check_taint_not ucfirst($a), 'ucfirst($a)';
420 check_taint_not "\u$a", '"\u$a"';
421 check_taint_not lc($a), 'lc($a)';
422 check_taint_not fc($a), 'fc($a)';
423 check_taint_not "\L$a", '"\L$a"';
424 check_taint_not "\F$a", '"\F$a"';
425 check_taint_not lcfirst($a), 'lcfirst($a)';
426 check_taint_not "\l$a", '"\l$a"';
428 check_taint_not sprintf('%e', 123.456), "sprintf('%e', 123.456)";
429 check_taint_not sprintf('%f', 123.456), "sprintf('%f', 123.456)";
430 check_taint_not sprintf('%g', 123.456), "sprintf('%g', 123.456)";
431 check_taint_not sprintf('%d', 123.456), "sprintf('%d', 123.456)";
432 check_taint_not sprintf('%x', 123.456), "sprintf('%x', 123.456)";
434 $_ = $a; # untaint $_
438 check_taint_not $_, '$_ = uc($a)';
441 check_taint_not $&, "\$& from /(\\w)/";
442 check_taint_not $`, "\t\$`";
443 check_taint_not $', "\t\$'";
444 check_taint_not $+, "\t\$+";
445 check_taint_not $1, "\t\$1";
446 check_taint_not $2, "\t\$2";
448 /(.)/; # untaint $&, $`, $', $+, $1.
449 check_taint_not $&, "\$& from /(.)/";
450 check_taint_not $`, "\t\$`";
451 check_taint_not $', "\t\$'";
452 check_taint_not $+, "\t\$+";
453 check_taint_not $1, "\t\$1";
454 check_taint_not $2, "\t\$2";
457 check_taint_not $&, "\$& from /(\\W)/";
458 check_taint_not $`, "\t\$`";
459 check_taint_not $', "\t\$'";
460 check_taint_not $+, "\t\$+";
461 check_taint_not $1, "\t\$1";
462 check_taint_not $2, "\t\$2";
464 /(.)/; # untaint $&, $`, $', $+, $1.
465 check_taint_not $&, "\$& from /(.)/";
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";
473 check_taint_not $&, "\$& from /(\\s)/";
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";
480 /(.)/; # untaint $&, $`, $', $+, $1.
481 check_taint_not $&, "\$& from /(.)/";
484 check_taint_not $&, "\$& from /(\\S)/";
485 check_taint_not $`, "\t\$`";
486 check_taint_not $', "\t\$'";
487 check_taint_not $+, "\t\$+";
488 check_taint_not $1, "\t\$1";
489 check_taint_not $2, "\t\$2";
491 /(.)/; # untaint $&, $`, $', $+, $1.
492 check_taint_not $&, "\$& from /(.)/";
495 check_taint_not $&, "\$& from /(\\d)/";
496 check_taint_not $`, "\t\$`";
497 check_taint_not $', "\t\$'";
498 check_taint_not $+, "\t\$+";
499 check_taint_not $1, "\t\$1";
500 check_taint_not $2, "\t\$2";
502 /(.)/; # untaint $&, $`, $', $+, $1.
503 check_taint_not $&, "\$& from /(.)/";
506 check_taint_not $&, "\$& from /(\\D)/";
507 check_taint_not $`, "\t\$`";
508 check_taint_not $', "\t\$'";
509 check_taint_not $+, "\t\$+";
510 check_taint_not $1, "\t\$1";
511 check_taint_not $2, "\t\$2";
513 /(.)/; # untaint $&, $`, $', $+, $1.
514 check_taint_not $&, "\$& from /(.)/";
517 check_taint_not $&, "\$& from /([[:alnum:]])/";
518 check_taint_not $`, "\t\$`";
519 check_taint_not $', "\t\$'";
520 check_taint_not $+, "\t\$+";
521 check_taint_not $1, "\t\$1";
522 check_taint_not $2, "\t\$2";
524 /(.)/; # untaint $&, $`, $', $+, $1.
525 check_taint_not $&, "\$& from /(.)/";
528 check_taint_not $&, "\$& from /([[:^alnum:]])/";
529 check_taint_not $`, "\t\$`";
530 check_taint_not $', "\t\$'";
531 check_taint_not $+, "\t\$+";
532 check_taint_not $1, "\t\$1";
533 check_taint_not $2, "\t\$2";
536 check_taint_not $&, "\$& from /(a)|(\\w)/";
537 check_taint_not $`, "\t\$`";
538 check_taint_not $', "\t\$'";
539 check_taint_not $+, "\t\$+";
540 check_taint_not $1, "\t\$1";
541 ok($1 eq 'a', ("\t" x 5) . "\$1 is 'a'");
542 ok(! defined $2, ("\t" x 5) . "\$2 is undefined");
543 check_taint_not $2, "\t\$2";
544 check_taint_not $3, "\t\$3";
546 /(.)/; # untaint $&, $`, $', $+, $1.
547 check_taint_not $&, "\$& from /(.)/";
549 "\N{CYRILLIC SMALL LETTER A}" =~ /(\N{CYRILLIC CAPITAL LETTER A})/i;
550 check_taint_not $&, "\$& from /(\\N{CYRILLIC CAPITAL LETTER A})/i";
551 check_taint_not $`, "\t\$`";
552 check_taint_not $', "\t\$'";
553 check_taint_not $+, "\t\$+";
554 check_taint_not $1, "\t\$1";
555 ok($1 eq "\N{CYRILLIC SMALL LETTER A}", ("\t" x 4) . "\t\$1 is 'small cyrillic a'");
556 check_taint_not $2, "\t\$2";
558 /(.)/; # untaint $&, $`, $', $+, $1.
559 check_taint_not $&, "\$& from /./";
561 "(\N{KELVIN SIGN})" =~ /(\N{KELVIN SIGN})/i;
562 check_taint_not $&, "\$& from /(\\N{KELVIN SIGN})/i";
563 check_taint_not $`, "\t\$`";
564 check_taint_not $', "\t\$'";
565 check_taint_not $+, "\t\$+";
566 check_taint_not $1, "\t\$1";
567 check_taint_not $2, "\t\$2";
569 /(.)/; # untaint $&, $`, $', $+, $1.
570 check_taint_not $&, "\$& from /(.)/";
573 check_taint_not $&, "\$& from /(.)\\b(.)/";
574 check_taint_not $`, "\t\$`";
575 check_taint_not $', "\t\$'";
576 check_taint_not $+, "\t\$+";
577 check_taint_not $1, "\t\$1";
578 check_taint_not $2, "\t\$2";
579 check_taint_not $3, "\t\$3";
581 /(.)/; # untaint $&, $`, $', $+, $1.
582 check_taint_not $&, "\$& from /./";
585 check_taint_not $&, "\$& from /(.)\\B(.)/";
586 check_taint_not $`, "\t\$`";
587 check_taint_not $', "\t\$'";
588 check_taint_not $+, "\t\$+";
589 check_taint_not $1, "\t\$1";
590 check_taint_not $2, "\t\$2";
591 check_taint_not $3, "\t\$3";
593 /(.)/; # untaint $&, $`, $', $+, $1.
594 check_taint_not $&, "\$& from /./";
596 "aaa" =~ /(.).(\1)/i; # notaint because not locale dependent
597 check_taint_not $&, "\$ & from /(.).(\\1)/";
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 /./";
608 $_ = $a; # untaint $_
610 check_taint_not $_, 'untainting $_ works';
613 check_taint_not $&, "\$ & from /(b)/";
614 check_taint_not $`, "\t\$`";
615 check_taint_not $', "\t\$'";
616 check_taint_not $+, "\t\$+";
617 check_taint_not $1, "\t\$1";
618 check_taint_not $2, "\t\$2";
620 $_ = $a; # untaint $_
622 check_taint_not $_, 'untainting $_ works';
625 check_taint_not $_, '$_ (wasn\'t tainted) from s/(.+)/b/';
626 check_taint_not $&, "\t\$&";
627 check_taint_not $`, "\t\$`";
628 check_taint_not $', "\t\$'";
629 check_taint_not $+, "\t\$+";
630 check_taint_not $1, "\t\$1";
631 check_taint_not $2, "\t\$2";
633 $b = $a; # untaint $b
635 ($b = $a) =~ s/\w/$&/;
636 check_taint_not $b, '$b from ($b = $a) =~ s/\w/$&/';
637 check_taint_not $a, '$a from ($b = $a) =~ s/\w/$&/';
639 $_ = $a; # untaint $_
642 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\l$1/,'; # this must taint
643 check_taint_not $&, "\t\$&";
644 check_taint_not $`, "\t\$`";
645 check_taint_not $', "\t\$'";
646 check_taint_not $+, "\t\$+";
647 check_taint_not $1, "\t\$1";
648 check_taint_not $2, "\t\$2";
650 $_ = $a; # untaint $_
653 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\L$1/,';
654 check_taint_not $&, "\t\$&";
655 check_taint_not $`, "\t\$`";
656 check_taint_not $', "\t\$'";
657 check_taint_not $+, "\t\$+";
658 check_taint_not $1, "\t\$1";
659 check_taint_not $2, "\t\$2";
661 $_ = $a; # untaint $_
664 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\u$1/';
665 check_taint_not $&, "\t\$&";
666 check_taint_not $`, "\t\$`";
667 check_taint_not $', "\t\$'";
668 check_taint_not $+, "\t\$+";
669 check_taint_not $1, "\t\$1";
670 check_taint_not $2, "\t\$2";
672 $_ = $a; # untaint $_
675 check_taint_not $_, '$_ (wasn\'t tainted) from s/(\w)/\U$1/';
676 check_taint_not $&, "\t\$&";
677 check_taint_not $`, "\t\$`";
678 check_taint_not $', "\t\$'";
679 check_taint_not $+, "\t\$+";
680 check_taint_not $1, "\t\$1";
681 check_taint_not $2, "\t\$2";
683 # After all this tainting $a should be cool.
685 check_taint_not $a, '$a still not tainted';
688 check_taint_not $1, '"a" =~ /([a-z])/';
689 "foo.bar_baz" =~ /^(.*)[._](.*?)$/; # Bug 120675
690 check_taint_not $1, '"foo.bar_baz" =~ /^(.*)[._](.*?)$/';
694 # Here are in scope of 'use locale'
696 # I think we've seen quite enough of taint.
697 # Let us do some *real* locale work now,
698 # unless setlocale() is missing (i.e. minitest).
700 # The test number before our first setlocale()
701 my $final_without_setlocale = $test_num;
705 debug "# Scanning for locales...\n";
707 require POSIX; import POSIX ':locale_h';
709 my @Locale = find_locales([ &POSIX::LC_CTYPE, &POSIX::LC_ALL ]);
711 debug "# Locales =\n";
717 print "1..$test_num\n";
722 setlocale(&POSIX::LC_ALL, "C");
729 my @Added_alpha; # Alphas that aren't in the C locale.
733 # This returns a display string denoting the input parameter @_, each
734 # entry of which is a single character in the range 0-255. The first part
735 # of the output is a string of the characters in @_ that are ASCII
736 # graphics, and hence unambiguously displayable. They are given by code
737 # point order. The second part is the remaining code points, the ordinals
738 # of which are each displayed as 2-digit hex. Blanks are inserted so as
739 # to keep anything from the first part looking like a 2-digit hex number.
742 my @chars = sort { ord $a <=> ord $b } @_;
746 push @chars, chr(258); # This sentinel simplifies the loop termination
748 foreach my $i (0 .. @chars - 1) {
749 my $char = $chars[$i];
753 # We avoid using [:posix:] classes, as these are being tested in this
754 # file. Each equivalence class below is for things that can appear in
755 # a range; those that can't be in a range have class -1. 0 for those
756 # which should be output in hex; and >0 for the other ranges
757 if ($char =~ /[A-Z]/) {
760 elsif ($char =~ /[a-z]/) {
763 elsif ($char =~ /[0-9]/) {
766 # Uncomment to get literal punctuation displayed instead of hex
767 #elsif ($char =~ /[[\]!"#\$\%&\'()*+,.\/:\\;<=>?\@\^_`{|}~-]/) {
768 # $class = -1; # Punct never appears in a range
771 $class = 0; # Output in hex
774 if (! defined $range_start) {
776 $output .= " " . $char;
779 $range_start = ord $char;
780 $start_class = $class;
782 } # A range ends if not consecutive, or the class-type changes
783 elsif (ord $char != ($range_end = ord($chars[$i-1])) + 1
784 || $class != $start_class)
787 # Here, the current character is not in the range. This means the
788 # previous character must have been. Output the range up through
790 my $range_length = $range_end - $range_start + 1;
791 if ($start_class > 0) {
792 $output .= " " . chr($range_start);
793 $output .= "-" . chr($range_end) if $range_length > 1;
796 $output .= sprintf(" %02X", $range_start);
797 $output .= sprintf("-%02X", $range_end) if $range_length > 1;
800 # Handle the new current character, as potentially beginning a new
812 my ($Locale, $i, $pass_fail, $message) = @_;
814 $message = " ($message)" if $message;
815 unless ($pass_fail) {
816 $Problem{$i}{$Locale} = 1;
817 debug "# failed $i ($test_names{$i}) with locale '$Locale'$message\n";
819 push @{$Okay{$i}}, $Locale;
823 sub report_multi_result {
824 my ($Locale, $i, $results_ref) = @_;
826 # $results_ref points to an array, each element of which is a character that was
827 # in error for this test numbered '$i'. If empty, the test passed
831 $message = join " ", "for", disp_chars(@$results_ref);
833 report_result($Locale, $i, @$results_ref == 0, $message);
836 my $first_locales_test_number = $final_without_setlocale + 1;
837 my $locales_test_number;
838 my $not_necessarily_a_problem_test_number;
839 my $first_casing_test_number;
840 my %setlocale_failed; # List of locales that setlocale() didn't work on
842 foreach my $Locale (@Locale) {
843 $locales_test_number = $first_locales_test_number - 1;
845 debug "# Locale = $Locale\n";
847 unless (setlocale(&POSIX::LC_ALL, $Locale)) {
848 $setlocale_failed{$Locale} = $Locale;
852 # We test UTF-8 locales only under ':not_characters'; It is easier to
853 # test them in other test files than here. Non- UTF-8 locales are tested
854 # only under plain 'use locale', as otherwise we would have to convert
855 # everything in them to Unicode.
857 my %UPPER = (); # All alpha X for which uc(X) == X and lc(X) != X
858 my %lower = (); # All alpha X for which lc(X) == X and uc(X) != X
859 my %BoThCaSe = (); # All alpha X for which uc(X) == lc(X) == X
861 my $is_utf8_locale = is_locale_utf8($Locale);
863 debug "# is utf8 locale? = $is_utf8_locale\n";
865 my $radix = localeconv()->{decimal_point};
866 if ($radix !~ / ^ [[:ascii:]] + $/x) {
868 $radix = disp_chars(split "", $radix);
870 debug "# radix = $radix\n";
872 if (! $is_utf8_locale) {
874 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
875 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
876 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
877 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
878 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
879 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
880 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
881 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
882 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
883 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
884 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
885 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
886 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
887 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
888 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
890 # Sieve the uppercase and the lowercase.
892 for (@{$posixes{'word'}}) {
893 if (/[^\d_]/) { # skip digits and the _
904 use locale ':not_characters';
905 @{$posixes{'word'}} = grep /\w/, map { chr } 0..255;
906 @{$posixes{'digit'}} = grep /\d/, map { chr } 0..255;
907 @{$posixes{'space'}} = grep /\s/, map { chr } 0..255;
908 @{$posixes{'alpha'}} = grep /[[:alpha:]]/, map {chr } 0..255;
909 @{$posixes{'alnum'}} = grep /[[:alnum:]]/, map {chr } 0..255;
910 @{$posixes{'ascii'}} = grep /[[:ascii:]]/, map {chr } 0..255;
911 @{$posixes{'blank'}} = grep /[[:blank:]]/, map {chr } 0..255;
912 @{$posixes{'cntrl'}} = grep /[[:cntrl:]]/, map {chr } 0..255;
913 @{$posixes{'graph'}} = grep /[[:graph:]]/, map {chr } 0..255;
914 @{$posixes{'lower'}} = grep /[[:lower:]]/, map {chr } 0..255;
915 @{$posixes{'print'}} = grep /[[:print:]]/, map {chr } 0..255;
916 @{$posixes{'punct'}} = grep /[[:punct:]]/, map {chr } 0..255;
917 @{$posixes{'upper'}} = grep /[[:upper:]]/, map {chr } 0..255;
918 @{$posixes{'xdigit'}} = grep /[[:xdigit:]]/, map {chr } 0..255;
919 @{$posixes{'cased'}} = grep /[[:upper:]]/i, map {chr } 0..255;
920 for (@{$posixes{'word'}}) {
921 if (/[^\d_]/) { # skip digits and the _
932 # Ordered, where possible, in groups of "this is a subset of the next
934 debug "# :upper: = ", disp_chars(@{$posixes{'upper'}}), "\n";
935 debug "# :lower: = ", disp_chars(@{$posixes{'lower'}}), "\n";
936 debug "# :cased: = ", disp_chars(@{$posixes{'cased'}}), "\n";
937 debug "# :alpha: = ", disp_chars(@{$posixes{'alpha'}}), "\n";
938 debug "# :alnum: = ", disp_chars(@{$posixes{'alnum'}}), "\n";
939 debug "# w = ", disp_chars(@{$posixes{'word'}}), "\n";
940 debug "# :graph: = ", disp_chars(@{$posixes{'graph'}}), "\n";
941 debug "# :print: = ", disp_chars(@{$posixes{'print'}}), "\n";
942 debug "# d = ", disp_chars(@{$posixes{'digit'}}), "\n";
943 debug "# :xdigit: = ", disp_chars(@{$posixes{'xdigit'}}), "\n";
944 debug "# :blank: = ", disp_chars(@{$posixes{'blank'}}), "\n";
945 debug "# s = ", disp_chars(@{$posixes{'space'}}), "\n";
946 debug "# :punct: = ", disp_chars(@{$posixes{'punct'}}), "\n";
947 debug "# :cntrl: = ", disp_chars(@{$posixes{'cntrl'}}), "\n";
948 debug "# :ascii: = ", disp_chars(@{$posixes{'ascii'}}), "\n";
950 foreach (keys %UPPER) {
952 $BoThCaSe{$_}++ if exists $lower{$_};
954 foreach (keys %lower) {
955 $BoThCaSe{$_}++ if exists $UPPER{$_};
957 foreach (keys %BoThCaSe) {
963 foreach my $ord ( 0 .. 255 ) {
964 $Unassigned{chr $ord} = 1;
966 foreach my $class (keys %posixes) {
967 foreach my $char (@{$posixes{$class}}) {
968 delete $Unassigned{$char};
972 debug "# UPPER = ", disp_chars(sort { ord $a <=> ord $b } keys %UPPER), "\n";
973 debug "# lower = ", disp_chars(sort { ord $a <=> ord $b } keys %lower), "\n";
974 debug "# BoThCaSe = ", disp_chars(sort { ord $a <=> ord $b } keys %BoThCaSe), "\n";
975 debug "# Unassigned = ", disp_chars(sort { ord $a <=> ord $b } keys %Unassigned), "\n";
979 foreach my $x (sort { ord $a <=> ord $b } keys %UPPER) {
982 if ($is_utf8_locale) {
983 use locale ':not_characters';
984 $ok = $x =~ /[[:upper:]]/;
985 $fold_ok = $x =~ /[[:lower:]]/i;
989 $ok = $x =~ /[[:upper:]]/;
990 $fold_ok = $x =~ /[[:lower:]]/i;
992 push @failures, $x unless $ok;
993 push @fold_failures, $x unless $fold_ok;
995 $locales_test_number++;
996 $first_casing_test_number = $locales_test_number;
997 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/ matches all alpha X for which uc(X) == X and lc(X) != X';
998 report_multi_result($Locale, $locales_test_number, \@failures);
1000 $locales_test_number++;
1002 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i matches all alpha X for which uc(X) == X and lc(X) != X';
1003 report_multi_result($Locale, $locales_test_number, \@fold_failures);
1006 undef @fold_failures;
1008 foreach my $x (sort { ord $a <=> ord $b } keys %lower) {
1011 if ($is_utf8_locale) {
1012 use locale ':not_characters';
1013 $ok = $x =~ /[[:lower:]]/;
1014 $fold_ok = $x =~ /[[:upper:]]/i;
1018 $ok = $x =~ /[[:lower:]]/;
1019 $fold_ok = $x =~ /[[:upper:]]/i;
1021 push @failures, $x unless $ok;
1022 push @fold_failures, $x unless $fold_ok;
1025 $locales_test_number++;
1026 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/ matches all alpha X for which lc(X) == X and uc(X) != X';
1027 report_multi_result($Locale, $locales_test_number, \@failures);
1029 $locales_test_number++;
1030 $test_names{$locales_test_number} = 'Verify that /[[:upper:]]/i matches all alpha X for which lc(X) == X and uc(X) != X';
1031 report_multi_result($Locale, $locales_test_number, \@fold_failures);
1033 { # Find the alphabetic characters that are not considered alphabetics
1034 # in the default (C) locale.
1039 for (keys %UPPER, keys %lower, keys %BoThCaSe) {
1040 push(@Added_alpha, $_) if (/\W/);
1044 @Added_alpha = sort { ord $a <=> ord $b } @Added_alpha;
1046 debug "# Added_alpha = ", disp_chars(@Added_alpha), "\n";
1048 # Cross-check the whole 8-bit character set.
1050 ++$locales_test_number;
1052 $test_names{$locales_test_number} = 'Verify that \w and [:word:] are identical';
1053 for (map { chr } 0..255) {
1054 if ($is_utf8_locale) {
1055 use locale ':not_characters';
1056 push @f, $_ unless /[[:word:]]/ == /\w/;
1059 push @f, $_ unless /[[:word:]]/ == /\w/;
1062 report_multi_result($Locale, $locales_test_number, \@f);
1064 ++$locales_test_number;
1066 $test_names{$locales_test_number} = 'Verify that \d and [:digit:] are identical';
1067 for (map { chr } 0..255) {
1068 if ($is_utf8_locale) {
1069 use locale ':not_characters';
1070 push @f, $_ unless /[[:digit:]]/ == /\d/;
1073 push @f, $_ unless /[[:digit:]]/ == /\d/;
1076 report_multi_result($Locale, $locales_test_number, \@f);
1078 ++$locales_test_number;
1080 $test_names{$locales_test_number} = 'Verify that \s and [:space:] are identical';
1081 for (map { chr } 0..255) {
1082 if ($is_utf8_locale) {
1083 use locale ':not_characters';
1084 push @f, $_ unless /[[:space:]]/ == /\s/;
1087 push @f, $_ unless /[[:space:]]/ == /\s/;
1090 report_multi_result($Locale, $locales_test_number, \@f);
1092 ++$locales_test_number;
1094 $test_names{$locales_test_number} = 'Verify that [:posix:] and [:^posix:] are mutually exclusive';
1095 for (map { chr } 0..255) {
1096 if ($is_utf8_locale) {
1097 use locale ':not_characters';
1098 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
1099 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
1100 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
1101 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
1102 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
1103 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
1104 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
1105 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
1106 (/[[:print:]]/ xor /[[:^print:]]/) ||
1107 (/[[:space:]]/ xor /[[:^space:]]/) ||
1108 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
1109 (/[[:word:]]/ xor /[[:^word:]]/) ||
1110 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1112 # effectively is what [:cased:] would be if it existed.
1113 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1116 push @f, $_ unless (/[[:alpha:]]/ xor /[[:^alpha:]]/) ||
1117 (/[[:alnum:]]/ xor /[[:^alnum:]]/) ||
1118 (/[[:ascii:]]/ xor /[[:^ascii:]]/) ||
1119 (/[[:blank:]]/ xor /[[:^blank:]]/) ||
1120 (/[[:cntrl:]]/ xor /[[:^cntrl:]]/) ||
1121 (/[[:digit:]]/ xor /[[:^digit:]]/) ||
1122 (/[[:graph:]]/ xor /[[:^graph:]]/) ||
1123 (/[[:lower:]]/ xor /[[:^lower:]]/) ||
1124 (/[[:print:]]/ xor /[[:^print:]]/) ||
1125 (/[[:space:]]/ xor /[[:^space:]]/) ||
1126 (/[[:upper:]]/ xor /[[:^upper:]]/) ||
1127 (/[[:word:]]/ xor /[[:^word:]]/) ||
1128 (/[[:xdigit:]]/ xor /[[:^xdigit:]]/) ||
1129 (/[[:upper:]]/i xor /[[:^upper:]]/i);
1132 report_multi_result($Locale, $locales_test_number, \@f);
1134 # The rules for the relationships are given in:
1135 # http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html
1138 ++$locales_test_number;
1140 $test_names{$locales_test_number} = 'Verify that [:lower:] contains at least a-z';
1142 if ($is_utf8_locale) {
1143 use locale ':not_characters';
1144 push @f, $_ unless /[[:lower:]]/;
1147 push @f, $_ unless /[[:lower:]]/;
1150 report_multi_result($Locale, $locales_test_number, \@f);
1152 ++$locales_test_number;
1154 $test_names{$locales_test_number} = 'Verify that [:lower:] is a subset of [:alpha:]';
1155 for (map { chr } 0..255) {
1156 if ($is_utf8_locale) {
1157 use locale ':not_characters';
1158 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1161 push @f, $_ if /[[:lower:]]/ and ! /[[:alpha:]]/;
1164 report_multi_result($Locale, $locales_test_number, \@f);
1166 ++$locales_test_number;
1168 $test_names{$locales_test_number} = 'Verify that [:upper:] contains at least A-Z';
1170 if ($is_utf8_locale) {
1171 use locale ':not_characters';
1172 push @f, $_ unless /[[:upper:]]/;
1175 push @f, $_ unless /[[:upper:]]/;
1178 report_multi_result($Locale, $locales_test_number, \@f);
1180 ++$locales_test_number;
1182 $test_names{$locales_test_number} = 'Verify that [:upper:] is a subset of [:alpha:]';
1183 for (map { chr } 0..255) {
1184 if ($is_utf8_locale) {
1185 use locale ':not_characters';
1186 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1189 push @f, $_ if /[[:upper:]]/ and ! /[[:alpha:]]/;
1192 report_multi_result($Locale, $locales_test_number, \@f);
1194 ++$locales_test_number;
1196 $test_names{$locales_test_number} = 'Verify that /[[:lower:]]/i is a subset of [:alpha:]';
1197 for (map { chr } 0..255) {
1198 if ($is_utf8_locale) {
1199 use locale ':not_characters';
1200 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1203 push @f, $_ if /[[:lower:]]/i and ! /[[:alpha:]]/;
1206 report_multi_result($Locale, $locales_test_number, \@f);
1208 ++$locales_test_number;
1210 $test_names{$locales_test_number} = 'Verify that [:alpha:] is a subset of [:alnum:]';
1211 for (map { chr } 0..255) {
1212 if ($is_utf8_locale) {
1213 use locale ':not_characters';
1214 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1217 push @f, $_ if /[[:alpha:]]/ and ! /[[:alnum:]]/;
1220 report_multi_result($Locale, $locales_test_number, \@f);
1222 ++$locales_test_number;
1224 $test_names{$locales_test_number} = 'Verify that [:digit:] contains at least 0-9';
1226 if ($is_utf8_locale) {
1227 use locale ':not_characters';
1228 push @f, $_ unless /[[:digit:]]/;
1231 push @f, $_ unless /[[:digit:]]/;
1234 report_multi_result($Locale, $locales_test_number, \@f);
1236 ++$locales_test_number;
1238 $test_names{$locales_test_number} = 'Verify that [:digit:] is a subset of [:alnum:]';
1239 for (map { chr } 0..255) {
1240 if ($is_utf8_locale) {
1241 use locale ':not_characters';
1242 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1245 push @f, $_ if /[[:digit:]]/ and ! /[[:alnum:]]/;
1248 report_multi_result($Locale, $locales_test_number, \@f);
1250 ++$locales_test_number;
1252 $test_names{$locales_test_number} = 'Verify that [:digit:] matches either 10 or 20 code points';
1253 report_result($Locale, $locales_test_number, @{$posixes{'digit'}} == 10 || @{$posixes{'digit'}} == 20);
1255 ++$locales_test_number;
1257 $test_names{$locales_test_number} = 'Verify that if there is a second set of digits in [:digit:], they are consecutive';
1258 if (@{$posixes{'digit'}} == 20) {
1260 for (map { chr } 0..255) {
1261 next unless /[[:digit:]]/;
1263 if (defined $previous_ord) {
1264 if ($is_utf8_locale) {
1265 use locale ':not_characters';
1266 push @f, $_ if ord $_ != $previous_ord + 1;
1269 push @f, $_ if ord $_ != $previous_ord + 1;
1272 $previous_ord = ord $_;
1275 report_multi_result($Locale, $locales_test_number, \@f);
1277 ++$locales_test_number;
1279 my @xdigit_digits; # :digit: & :xdigit:
1280 $test_names{$locales_test_number} = 'Verify that [:xdigit:] contains one or two blocks of 10 consecutive [:digit:] chars';
1281 for (map { chr } 0..255) {
1282 if ($is_utf8_locale) {
1283 use locale ':not_characters';
1284 # For utf8 locales, we actually use a stricter test: that :digit:
1285 # is a subset of :xdigit:, as we know that only 0-9 should match
1286 push @f, $_ if /[[:digit:]]/ and ! /[[:xdigit:]]/;
1289 push @xdigit_digits, $_ if /[[:digit:]]/ and /[[:xdigit:]]/;
1292 if (! $is_utf8_locale) {
1294 # For non-utf8 locales, @xdigit_digits is a list of the characters
1295 # that are both :xdigit: and :digit:. Because :digit: is stored in
1296 # increasing code point order (unless the tests above failed),
1297 # @xdigit_digits is as well. There should be exactly 10 or
1299 if (@xdigit_digits != 10 && @xdigit_digits != 20) {
1300 @f = @xdigit_digits;
1304 # Look for contiguity in the series, adding any wrong ones to @f
1305 my @temp = @xdigit_digits;
1307 push @f, $temp[1] if ($temp[0] != $temp[1] - 1)
1309 # Skip this test for the 0th character of
1310 # the second block of 10, as it won't be
1311 # contiguous with the previous block
1312 && (! defined $xdigit_digits[10]
1313 || $temp[1] != $xdigit_digits[10]);
1319 report_multi_result($Locale, $locales_test_number, \@f);
1321 ++$locales_test_number;
1323 $test_names{$locales_test_number} = 'Verify that [:xdigit:] contains at least A-F, a-f';
1324 for ('A' .. 'F', 'a' .. 'f') {
1325 if ($is_utf8_locale) {
1326 use locale ':not_characters';
1327 push @f, $_ unless /[[:xdigit:]]/;
1330 push @f, $_ unless /[[:xdigit:]]/;
1333 report_multi_result($Locale, $locales_test_number, \@f);
1335 ++$locales_test_number;
1337 $test_names{$locales_test_number} = 'Verify that any additional members of [:xdigit:], are in groups of 6 consecutive code points';
1340 for my $chr (map { chr } 0..255) {
1341 next unless $chr =~ /[[:xdigit:]]/;
1342 if ($is_utf8_locale) {
1343 next if $chr =~ /[[:digit:]]/;
1346 next if grep { $chr eq $_ } @xdigit_digits;
1348 next if $chr =~ /[A-Fa-f]/;
1349 if (defined $previous_ord) {
1350 if ($is_utf8_locale) {
1351 use locale ':not_characters';
1352 push @f, $chr if ord $chr != $previous_ord + 1;
1355 push @f, $chr if ord $chr != $previous_ord + 1;
1360 undef $previous_ord;
1363 $previous_ord = ord $chr;
1366 report_multi_result($Locale, $locales_test_number, \@f);
1368 ++$locales_test_number;
1370 $test_names{$locales_test_number} = 'Verify that [:xdigit:] is a subset of [:graph:]';
1371 for (map { chr } 0..255) {
1372 if ($is_utf8_locale) {
1373 use locale ':not_characters';
1374 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1377 push @f, $_ if /[[:xdigit:]]/ and ! /[[:graph:]]/;
1380 report_multi_result($Locale, $locales_test_number, \@f);
1382 # Note that xdigit doesn't have to be a subset of alnum
1384 ++$locales_test_number;
1386 $test_names{$locales_test_number} = 'Verify that [:punct:] is a subset of [:graph:]';
1387 for (map { chr } 0..255) {
1388 if ($is_utf8_locale) {
1389 use locale ':not_characters';
1390 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1393 push @f, $_ if /[[:punct:]]/ and ! /[[:graph:]]/;
1396 report_multi_result($Locale, $locales_test_number, \@f);
1398 ++$locales_test_number;
1400 $test_names{$locales_test_number} = 'Verify that the space character is not in [:graph:]';
1401 if ($is_utf8_locale) {
1402 use locale ':not_characters';
1403 push @f, " " if " " =~ /[[:graph:]]/;
1406 push @f, " " if " " =~ /[[:graph:]]/;
1408 report_multi_result($Locale, $locales_test_number, \@f);
1410 ++$locales_test_number;
1412 $test_names{$locales_test_number} = 'Verify that [:space:] contains at least [\f\n\r\t\cK ]';
1413 for (' ', "\f", "\n", "\r", "\t", "\cK") {
1414 if ($is_utf8_locale) {
1415 use locale ':not_characters';
1416 push @f, $_ unless /[[:space:]]/;
1419 push @f, $_ unless /[[:space:]]/;
1422 report_multi_result($Locale, $locales_test_number, \@f);
1424 ++$locales_test_number;
1426 $test_names{$locales_test_number} = 'Verify that [:blank:] contains at least [\t ]';
1428 if ($is_utf8_locale) {
1429 use locale ':not_characters';
1430 push @f, $_ unless /[[:blank:]]/;
1433 push @f, $_ unless /[[:blank:]]/;
1436 report_multi_result($Locale, $locales_test_number, \@f);
1438 ++$locales_test_number;
1440 $test_names{$locales_test_number} = 'Verify that [:blank:] is a subset of [:space:]';
1441 for (map { chr } 0..255) {
1442 if ($is_utf8_locale) {
1443 use locale ':not_characters';
1444 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1447 push @f, $_ if /[[:blank:]]/ and ! /[[:space:]]/;
1450 report_multi_result($Locale, $locales_test_number, \@f);
1452 ++$locales_test_number;
1454 $test_names{$locales_test_number} = 'Verify that [:graph:] is a subset of [:print:]';
1455 for (map { chr } 0..255) {
1456 if ($is_utf8_locale) {
1457 use locale ':not_characters';
1458 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1461 push @f, $_ if /[[:graph:]]/ and ! /[[:print:]]/;
1464 report_multi_result($Locale, $locales_test_number, \@f);
1466 ++$locales_test_number;
1468 $test_names{$locales_test_number} = 'Verify that the space character is in [:print:]';
1469 if ($is_utf8_locale) {
1470 use locale ':not_characters';
1471 push @f, " " if " " !~ /[[:print:]]/;
1474 push @f, " " if " " !~ /[[:print:]]/;
1476 report_multi_result($Locale, $locales_test_number, \@f);
1478 ++$locales_test_number;
1480 $test_names{$locales_test_number} = 'Verify that isn\'t both [:cntrl:] and [:print:]';
1481 for (map { chr } 0..255) {
1482 if ($is_utf8_locale) {
1483 use locale ':not_characters';
1484 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1487 push @f, $_ if (/[[:print:]]/ and /[[:cntrl:]]/);
1490 report_multi_result($Locale, $locales_test_number, \@f);
1492 ++$locales_test_number;
1494 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alpha:] and [:digit:]';
1495 for (map { chr } 0..255) {
1496 if ($is_utf8_locale) {
1497 use locale ':not_characters';
1498 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1501 push @f, $_ if /[[:alpha:]]/ and /[[:digit:]]/;
1504 report_multi_result($Locale, $locales_test_number, \@f);
1506 ++$locales_test_number;
1508 $test_names{$locales_test_number} = 'Verify that isn\'t both [:alnum:] and [:punct:]';
1509 for (map { chr } 0..255) {
1510 if ($is_utf8_locale) {
1511 use locale ':not_characters';
1512 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1515 push @f, $_ if /[[:alnum:]]/ and /[[:punct:]]/;
1518 report_multi_result($Locale, $locales_test_number, \@f);
1520 ++$locales_test_number;
1522 $test_names{$locales_test_number} = 'Verify that isn\'t both [:xdigit:] and [:punct:]';
1523 for (map { chr } 0..255) {
1524 if ($is_utf8_locale) {
1525 use locale ':not_characters';
1526 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1529 push @f, $_ if (/[[:punct:]]/ and /[[:xdigit:]]/);
1532 report_multi_result($Locale, $locales_test_number, \@f);
1534 ++$locales_test_number;
1536 $test_names{$locales_test_number} = 'Verify that isn\'t both [:graph:] and [:space:]';
1537 for (map { chr } 0..255) {
1538 if ($is_utf8_locale) {
1539 use locale ':not_characters';
1540 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1543 push @f, $_ if (/[[:graph:]]/ and /[[:space:]]/);
1546 report_multi_result($Locale, $locales_test_number, \@f);
1548 foreach ($first_casing_test_number..$locales_test_number) {
1549 $problematical_tests{$_} = 1;
1553 # Test for read-only scalars' locale vs non-locale comparisons.
1559 if ($is_utf8_locale) {
1560 use locale ':not_characters';
1561 $ok = ($a cmp "qwerty") == 0;
1565 $ok = ($a cmp "qwerty") == 0;
1567 report_result($Locale, ++$locales_test_number, $ok);
1568 $test_names{$locales_test_number} = 'Verify that cmp works with a read-only scalar; no- vs locale';
1572 my ($from, $to, $lesser, $greater,
1573 @test, %test, $test, $yes, $no, $sign);
1575 ++$locales_test_number;
1576 $test_names{$locales_test_number} = 'Verify that "le", "ne", etc work';
1577 $not_necessarily_a_problem_test_number = $locales_test_number;
1580 $from = int(($_*@{$posixes{'word'}})/10);
1581 $to = $from + int(@{$posixes{'word'}}/10);
1582 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1583 $lesser = join('', @{$posixes{'word'}}[$from..$to]);
1584 # Select a slice one character on.
1586 $to = $#{$posixes{'word'}} if ($to > $#{$posixes{'word'}});
1587 $greater = join('', @{$posixes{'word'}}[$from..$to]);
1588 if ($is_utf8_locale) {
1589 use locale ':not_characters';
1590 ($yes, $no, $sign) = ($lesser lt $greater
1592 : ("not ", " ", -1));
1596 ($yes, $no, $sign) = ($lesser lt $greater
1598 : ("not ", " ", -1));
1600 # all these tests should FAIL (return 0). Exact lt or gt cannot
1601 # be tested because in some locales, say, eacute and E may test
1605 $no.' ($lesser le $greater)', # 1
1606 'not ($lesser ne $greater)', # 2
1607 ' ($lesser eq $greater)', # 3
1608 $yes.' ($lesser ge $greater)', # 4
1609 $yes.' ($lesser ge $greater)', # 5
1610 $yes.' ($greater le $lesser )', # 7
1611 'not ($greater ne $lesser )', # 8
1612 ' ($greater eq $lesser )', # 9
1613 $no.' ($greater ge $lesser )', # 10
1614 'not (($lesser cmp $greater) == -($sign))' # 11
1616 @test{@test} = 0 x @test;
1618 for my $ti (@test) {
1619 if ($is_utf8_locale) {
1620 use locale ':not_characters';
1621 $test{$ti} = eval $ti;
1624 # Already in 'use locale';
1625 $test{$ti} = eval $ti;
1627 $test ||= $test{$ti}
1629 report_result($Locale, $locales_test_number, $test == 0);
1631 debug "# lesser = '$lesser'\n";
1632 debug "# greater = '$greater'\n";
1633 debug "# lesser cmp greater = ",
1634 $lesser cmp $greater, "\n";
1635 debug "# greater cmp lesser = ",
1636 $greater cmp $lesser, "\n";
1637 debug "# (greater) from = $from, to = $to\n";
1638 for my $ti (@test) {
1639 debugf("# %-40s %-4s", $ti,
1640 $test{$ti} ? 'FAIL' : 'ok');
1641 if ($ti =~ /\(\.*(\$.+ +cmp +\$[^\)]+)\.*\)/) {
1642 debugf("(%s == %4d)", $1, eval $1);
1681 if (! $is_utf8_locale) {
1684 my ($x, $y) = (1.23, 1.23);
1687 printf ''; # printf used to reset locale to "C"
1692 my $z = sprintf ''; # sprintf used to reset locale to "C"
1699 local $SIG{__WARN__} =
1705 # The == (among other ops) used to warn for locales
1706 # that had something else than "." as the radix character.
1730 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1732 $ok14 = $ok14_5 = $ok15 = $ok16 = 1; # Skip for non-utf8 locales
1736 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1738 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1741 use locale ':not_characters';
1743 my ($x, $y) = (1.23, 1.23);
1745 printf ''; # printf used to reset locale to "C"
1750 my $z = sprintf ''; # sprintf used to reset locale to "C"
1756 local $SIG{__WARN__} =
1782 $ok12 = abs(($f + $g) - 3.57) < 0.01;
1785 # Look for non-ASCII error messages, and verify that the first
1786 # such is in UTF-8 (the others almost certainly will be like the
1790 foreach my $err (keys %!) {
1792 $! = eval "&Errno::$err"; # Convert to strerror() output
1793 my $strerror = "$!";
1794 if ("$strerror" =~ /\P{ASCII}/) {
1795 $ok14 = utf8::is_utf8($strerror);
1797 $ok14_5 = "$!" !~ /\P{ASCII}/;
1802 # Similarly, we verify that a non-ASCII radix is in UTF-8. This
1803 # also catches if there is a disparity between sprintf and
1806 my $string_g = "$g";
1807 my $sprintf_g = sprintf("%g", $g);
1809 $ok15 = $string_g =~ / ^ \p{ASCII}+ $ /x || utf8::is_utf8($string_g);
1810 $ok16 = $sprintf_g eq $string_g;
1814 $ok17 = "1.5:1.25" eq sprintf("%g:%g", $h, $i);
1816 $ok18 = $j eq sprintf("%g:%g", $h, $i);
1819 report_result($Locale, ++$locales_test_number, $ok1);
1820 $test_names{$locales_test_number} = 'Verify that an intervening printf doesn\'t change assignment results';
1821 my $first_a_test = $locales_test_number;
1823 debug "# $first_a_test..$locales_test_number: \$a = $a, \$b = $b, Locale = $Locale\n";
1825 report_result($Locale, ++$locales_test_number, $ok2);
1826 $test_names{$locales_test_number} = 'Verify that an intervening sprintf doesn\'t change assignment results';
1828 my $first_c_test = $locales_test_number;
1830 report_result($Locale, ++$locales_test_number, $ok3);
1831 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a constant';
1832 $problematical_tests{$locales_test_number} = 1;
1834 report_result($Locale, ++$locales_test_number, $ok4);
1835 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar';
1836 $problematical_tests{$locales_test_number} = 1;
1838 report_result($Locale, ++$locales_test_number, $ok5);
1839 $test_names{$locales_test_number} = 'Verify that a different locale radix works when doing "==" with a scalar and an intervening sprintf';
1840 $problematical_tests{$locales_test_number} = 1;
1842 debug "# $first_c_test..$locales_test_number: \$c = $c, \$d = $d, Locale = $Locale\n";
1844 report_result($Locale, ++$locales_test_number, $ok6);
1845 $test_names{$locales_test_number} = 'Verify that can assign stringified under inner no-locale block';
1846 my $first_e_test = $locales_test_number;
1848 report_result($Locale, ++$locales_test_number, $ok7);
1849 $test_names{$locales_test_number} = 'Verify that "==" with a scalar still works in inner no locale';
1851 report_result($Locale, ++$locales_test_number, $ok8);
1852 $test_names{$locales_test_number} = 'Verify that "==" with a scalar and an intervening sprintf still works in inner no locale';
1853 $problematical_tests{$locales_test_number} = 1;
1855 debug "# $first_e_test..$locales_test_number: \$e = $e, no locale\n";
1857 report_result($Locale, ++$locales_test_number, $ok9);
1858 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a constant';
1859 $problematical_tests{$locales_test_number} = 1;
1860 my $first_f_test = $locales_test_number;
1862 report_result($Locale, ++$locales_test_number, $ok10);
1863 $test_names{$locales_test_number} = 'Verify that after a no-locale block, a different locale radix still works when doing "==" with a scalar';
1864 $problematical_tests{$locales_test_number} = 1;
1866 report_result($Locale, ++$locales_test_number, $ok11);
1867 $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';
1868 $problematical_tests{$locales_test_number} = 1;
1870 report_result($Locale, ++$locales_test_number, $ok12);
1871 $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';
1872 $problematical_tests{$locales_test_number} = 1;
1874 report_result($Locale, ++$locales_test_number, $ok13);
1875 $test_names{$locales_test_number} = 'Verify that don\'t get warning under "==" even if radix is not a dot';
1876 $problematical_tests{$locales_test_number} = 1;
1878 report_result($Locale, ++$locales_test_number, $ok14);
1879 $test_names{$locales_test_number} = 'Verify that non-ASCII UTF-8 error messages are in UTF-8';
1881 report_result($Locale, ++$locales_test_number, $ok14_5);
1882 $test_names{$locales_test_number} = '... and are ASCII outside "use locale"';
1884 report_result($Locale, ++$locales_test_number, $ok15);
1885 $test_names{$locales_test_number} = 'Verify that a number with a UTF-8 radix has a UTF-8 stringification';
1887 report_result($Locale, ++$locales_test_number, $ok16);
1888 $test_names{$locales_test_number} = 'Verify that a sprintf of a number with a UTF-8 radix yields UTF-8';
1890 report_result($Locale, ++$locales_test_number, $ok17);
1891 $test_names{$locales_test_number} = 'Verify that a sprintf of a number outside locale scope uses a dot radix';
1893 report_result($Locale, ++$locales_test_number, $ok18);
1894 $test_names{$locales_test_number} = 'Verify that a sprintf of a number back within locale scope uses locale radix';
1896 debug "# $first_f_test..$locales_test_number: \$f = $f, \$g = $g, back to locale = $Locale\n";
1898 # Does taking lc separately differ from taking
1899 # the lc "in-line"? (This was the bug 19990704.002, change #3568.)
1900 # The bug was in the caching of the 'o'-magic.
1901 if (! $is_utf8_locale) {
1907 return $lc0 cmp $lc1;
1911 return lc($_[0]) cmp lc($_[1]);
1918 report_result($Locale, ++$locales_test_number,
1919 lcA($x, $y) == 1 && lcB($x, $y) == 1 ||
1920 lcA($x, $z) == 0 && lcB($x, $z) == 0);
1923 use locale ':not_characters';
1928 return $lc0 cmp $lc1;
1932 return lc($_[0]) cmp lc($_[1]);
1939 report_result($Locale, ++$locales_test_number,
1940 lcC($x, $y) == 1 && lcD($x, $y) == 1 ||
1941 lcC($x, $z) == 0 && lcD($x, $z) == 0);
1943 $test_names{$locales_test_number} = 'Verify "lc(foo) cmp lc(bar)" is the same as using intermediaries for the cmp';
1945 # Does lc of an UPPER (if different from the UPPER) match
1946 # case-insensitively the UPPER, and does the UPPER match
1947 # case-insensitively the lc of the UPPER. And vice versa.
1951 my $re = qr/[\[\(\{\*\+\?\|\^\$\\]/;
1954 ++$locales_test_number;
1955 $test_names{$locales_test_number} = 'Verify case insensitive matching works';
1956 foreach my $x (sort { ord $a <=> ord $b } keys %UPPER) {
1957 if (! $is_utf8_locale) {
1959 next unless uc $y eq $x;
1960 debug_more( "# UPPER=", disp_chars(($x)),
1961 "; lc=", disp_chars(($y)), "; ",
1962 "; fc=", disp_chars((fc $x)), "; ",
1963 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
1964 $x =~ /$y/i ? 1 : 0,
1966 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
1967 $y =~ /$x/i ? 1 : 0,
1970 # If $x and $y contain regular expression characters
1971 # AND THEY lowercase (/i) to regular expression characters,
1972 # regcomp() will be mightily confused. No, the \Q doesn't
1973 # help here (maybe regex engine internal lowercasing
1974 # is done after the \Q?) An example of this happening is
1975 # the bg_BG (Bulgarian) locale under EBCDIC (OS/390 USS):
1976 # the chr(173) (the "[") is the lowercase of the chr(235).
1978 # Similarly losing EBCDIC locales include cs_cz, cs_CZ,
1979 # el_gr, el_GR, en_us.IBM-037 (!), en_US.IBM-037 (!),
1980 # et_ee, et_EE, hr_hr, hr_HR, hu_hu, hu_HU, lt_LT,
1981 # mk_mk, mk_MK, nl_nl.IBM-037, nl_NL.IBM-037,
1982 # pl_pl, pl_PL, ro_ro, ro_RO, ru_ru, ru_RU,
1983 # sk_sk, sk_SK, sl_si, sl_SI, tr_tr, tr_TR.
1985 # Similar things can happen even under (bastardised)
1986 # non-EBCDIC locales: in many European countries before the
1987 # advent of ISO 8859-x nationally customised versions of
1988 # ISO 646 were devised, reusing certain punctuation
1989 # characters for modified characters needed by the
1990 # country/language. For example, the "|" might have
1991 # stood for U+00F6 or LATIN SMALL LETTER O WITH DIAERESIS.
1993 if ($x =~ $re || $y =~ $re) {
1994 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
1997 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
1999 # fc is not a locale concept, so Perl uses lc for it.
2000 push @f, $x unless lc $x eq fc $x;
2003 use locale ':not_characters';
2005 next unless uc $y eq $x;
2006 debug_more( "# UPPER=", disp_chars(($x)),
2007 "; lc=", disp_chars(($y)), "; ",
2008 "; fc=", disp_chars((fc $x)), "; ",
2009 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
2010 $x =~ /$y/i ? 1 : 0,
2012 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
2013 $y =~ /$x/i ? 1 : 0,
2016 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
2018 # The places where Unicode's lc is different from fc are
2019 # skipped here by virtue of the 'next unless uc...' line above
2020 push @f, $x unless lc $x eq fc $x;
2024 foreach my $x (sort { ord $a <=> ord $b } keys %lower) {
2025 if (! $is_utf8_locale) {
2027 next unless lc $y eq $x;
2028 debug_more( "# lower=", disp_chars(($x)),
2029 "; uc=", disp_chars(($y)), "; ",
2030 "; fc=", disp_chars((fc $x)), "; ",
2031 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
2032 $x =~ /$y/i ? 1 : 0,
2034 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
2035 $y =~ /$x/i ? 1 : 0,
2037 if ($x =~ $re || $y =~ $re) { # See above.
2038 print "# Regex characters in '$x' or '$y', skipping test $locales_test_number for locale '$Locale'\n";
2041 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
2043 push @f, $x unless lc $x eq fc $x;
2046 use locale ':not_characters';
2048 next unless lc $y eq $x;
2049 debug_more( "# lower=", disp_chars(($x)),
2050 "; uc=", disp_chars(($y)), "; ",
2051 "; fc=", disp_chars((fc $x)), "; ",
2052 disp_chars(($x)), "=~/", disp_chars(($y)), "/i=",
2053 $x =~ /$y/i ? 1 : 0,
2055 disp_chars(($y)), "=~/", disp_chars(($x)), "/i=",
2056 $y =~ /$x/i ? 1 : 0,
2058 push @f, $x unless $x =~ /$y/i && $y =~ /$x/i;
2060 push @f, $x unless lc $x eq fc $x;
2063 report_multi_result($Locale, $locales_test_number, \@f);
2064 $problematical_tests{$locales_test_number} = 1;
2070 ++$locales_test_number;
2071 $test_names{$locales_test_number} = 'Verify atof with locale radix and negative exponent';
2072 $problematical_tests{$locales_test_number} = 1;
2074 my $radix = POSIX::localeconv()->{decimal_point};
2076 "3.14e+9", "3${radix}14e+9", "3.14e-9", "3${radix}14e-9",
2077 "-3.14e+9", "-3${radix}14e+9", "-3.14e-9", "-3${radix}14e-9",
2080 if (! $is_utf8_locale) {
2082 for my $num (@nums) {
2084 unless sprintf("%g", $num) =~ /3.+14/;
2088 use locale ':not_characters';
2089 for my $num (@nums) {
2091 unless sprintf("%g", $num) =~ /3.+14/;
2095 report_result($Locale, $locales_test_number, @f == 0);
2097 print "# failed $locales_test_number locale '$Locale' numbers @f\n"
2102 my $final_locales_test_number = $locales_test_number;
2104 # Recount the errors.
2106 foreach $test_num ($first_locales_test_number..$final_locales_test_number) {
2107 if (%setlocale_failed) {
2110 elsif ($Problem{$test_num} || !defined $Okay{$test_num} || !@{$Okay{$test_num}}) {
2111 if (defined $not_necessarily_a_problem_test_number
2112 && $test_num == $not_necessarily_a_problem_test_number)
2114 print "# The failure of test $not_necessarily_a_problem_test_number is not necessarily fatal.\n";
2115 print "# It usually indicates a problem in the environment,\n";
2116 print "# not in Perl itself.\n";
2118 if ($Okay{$test_num} && grep { $_ == $test_num } keys %problematical_tests) {
2119 no warnings 'experimental::autoderef';
2120 # Round to nearest .1%
2121 my $percent_fail = (int(.5 + (1000 * scalar(keys $Problem{$test_num})
2122 / scalar(@Locale))))
2124 if (! $debug && $percent_fail < $acceptable_failure_percentage)
2126 $test_names{$test_num} .= 'TODO';
2127 print "# ", 100 - $percent_fail, "% of locales pass the following test, so it is likely that the failures\n";
2128 print "# are errors in the locale definitions. The test is marked TODO, as the\n";
2129 print "# problem is not likely to be Perl's\n";
2134 print "# The code points that had this failure are given above. Look for lines\n";
2135 print "# that match 'failed $test_num'\n";
2138 print "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
2139 print "# Then look at that output for lines that match 'failed $test_num'\n";
2143 print "ok $test_num";
2144 if (defined $test_names{$test_num}) {
2145 # If TODO is in the test name, make it thus
2146 my $todo = $test_names{$test_num} =~ s/TODO\s*//;
2147 print " $test_names{$test_num}";
2148 print " # TODO" if $todo;
2153 $test_num = $final_locales_test_number;
2155 unless ( $^O =~ m!^(dragonfly|openbsd|bitrig|mirbsd)$! ) {
2159 local $SIG{__WARN__} = sub {
2160 $warned = $_[0] =~ /uninitialized/;
2162 my $z = "y" . setlocale(&POSIX::LC_ALL, "xyzzy");
2163 ok($warned, "variable set to setlocale(BAD LOCALE) is considered uninitialized");
2166 # Test that tainting and case changing works on utf8 strings. These tests are
2167 # placed last to avoid disturbing the hard-coded test numbers that existed at
2168 # the time these were added above this in this file.
2169 # This also tests that locale overrides unicode_strings in the same scope for
2171 setlocale(&POSIX::LC_ALL, "C");
2174 use feature 'unicode_strings';
2176 foreach my $function ("uc", "ucfirst", "lc", "lcfirst", "fc") {
2177 my @list; # List of code points to test for $function
2179 # Used to calculate the changed case for ASCII characters by using the
2180 # ord, instead of using one of the functions under test.
2181 my $ascii_case_change_delta;
2182 my $above_latin1_case_change_delta; # Same for the specific ords > 255
2185 # We test an ASCII character, which should change case;
2186 # a Latin1 character, which shouldn't change case under this C locale,
2187 # an above-Latin1 character that when the case is changed would cross
2188 # the 255/256 boundary, so doesn't change case
2189 # (the \x{149} is one of these, but changes into 2 characters, the
2190 # first one of which doesn't cross the boundary.
2191 # the final one in each list is an above-Latin1 character whose case
2192 # does change. The code below uses its position in its list as a
2193 # marker to indicate that it, unlike the other code points above
2194 # ASCII, has a successful case change
2196 # All casing operations under locale (but not :not_characters) should
2198 if ($function =~ /^u/) {
2199 @list = ("", "a", "\xe0", "\xff", "\x{fb00}", "\x{149}", "\x{101}");
2200 $ascii_case_change_delta = -32;
2201 $above_latin1_case_change_delta = -1;
2204 @list = ("", "A", "\xC0", "\x{17F}", "\x{100}");
2205 $ascii_case_change_delta = +32;
2206 $above_latin1_case_change_delta = +1;
2208 foreach my $is_utf8_locale (0 .. 1) {
2209 foreach my $j (0 .. $#list) {
2210 my $char = $list[$j];
2212 for my $encoded_in_utf8 (0 .. 1) {
2215 if (! $is_utf8_locale) {
2216 $should_be = ($j == $#list)
2217 ? chr(ord($char) + $above_latin1_case_change_delta)
2218 : (length $char == 0 || ord($char) > 127)
2220 : chr(ord($char) + $ascii_case_change_delta);
2222 # This monstrosity is in order to avoid using an eval,
2223 # which might perturb the results
2224 $changed = ($function eq "uc")
2226 : ($function eq "ucfirst")
2228 : ($function eq "lc")
2230 : ($function eq "lcfirst")
2232 : ($function eq "fc")
2234 : die("Unexpected function \"$function\"");
2240 # For utf8-locales the case changing functions
2241 # should work just like they do outside of locale.
2242 # Can use eval here because not testing it when
2244 $should_be = eval "$function('$char')";
2245 die "Unexpected eval error $@ from 'eval \"$function('$char')\"'" if $@;
2248 use locale ':not_characters';
2249 $changed = ($function eq "uc")
2251 : ($function eq "ucfirst")
2253 : ($function eq "lc")
2255 : ($function eq "lcfirst")
2257 : ($function eq "fc")
2259 : die("Unexpected function \"$function\"");
2261 ok($changed eq $should_be,
2262 "$function(\"$char\") in C locale "
2263 . (($is_utf8_locale)
2264 ? "(use locale ':not_characters'"
2266 . (($encoded_in_utf8)
2267 ? "; encoded in utf8)"
2268 : "; not encoded in utf8)")
2269 . " should be \"$should_be\", got \"$changed\"");
2271 # Tainting shouldn't happen for use locale :not_character
2274 ? check_taint($changed)
2275 : check_taint_not($changed);
2277 # Use UTF-8 next time through the loop
2278 utf8::upgrade($char);
2285 # Give final advice.
2289 foreach ($first_locales_test_number..$final_locales_test_number) {
2291 my @f = sort keys %{ $Problem{$_} };
2292 my $f = join(" ", @f);
2293 $f =~ s/(.{50,60}) /$1\n#\t/g;
2296 "# The locale ", (@f == 1 ? "definition" : "definitions"), "\n#\n",
2298 "# on your system may have errors because the locale test $_\n",
2299 "# \"$test_names{$_}\"\n",
2300 "# failed in ", (@f == 1 ? "that locale" : "those locales"),
2304 # If your users are not using these locales you are safe for the moment,
2305 # but please report this failure first to perlbug\@perl.com using the
2306 # perlbug script (as described in the INSTALL file) so that the exact
2307 # details of the failures can be sorted out first and then your operating
2308 # system supplier can be alerted about these anomalies.
2315 # Tell which locales were okay and which were not.
2320 foreach my $l (@Locale) {
2322 if ($setlocale_failed{$l}) {
2327 ($first_locales_test_number..$final_locales_test_number)
2329 $p++ if $Problem{$t}{$l};
2332 push @s, $l if $p == 0;
2333 push @F, $l unless $p == 0;
2337 my $s = join(" ", @s);
2338 $s =~ s/(.{50,60}) /$1\n#\t/g;
2341 "# The following locales\n#\n",
2343 "# tested okay.\n#\n",
2345 print "# None of your locales were fully okay.\n";
2349 my $F = join(" ", @F);
2350 $F =~ s/(.{50,60}) /$1\n#\t/g;
2354 $details = "# For more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=1.\n";
2356 elsif ($debug == 1) {
2357 $details = "# For even more details, rerun, with environment variable PERL_DEBUG_FULL_TEST=2.\n";
2361 "# The following locales\n#\n",
2363 "# had problems.\n#\n",
2366 print "# None of your locales were broken.\n";
2370 print "1..$test_num\n";