summaryrefslogtreecommitdiff
path: root/t/unicode-bom.t
blob: b7398cf9b1dd340e4ecdabacb483309ed0a3b0fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!perl -w

use strict;
use Test::More tests => 2;
use HTML::Parser;

SKIP: {
skip "This perl does not support Unicode", 2 if $] < 5.008;

my @parsed;
my $p = HTML::Parser->new(
  api_version => 3,
  start_h => [\@parsed, 'tag, attr'],
);

my @warn;
$SIG{__WARN__} = sub {
    push(@warn, $_[0]);
};

$p->parse("\xEF\xBB\xBF<head>Hi there</head>");
$p->eof;

#use Encode;
$p->parse("\xEF\xBB\xBF<head>Hi there</head>" . chr(0x263A));
$p->eof;

$p->parse("\xFF\xFE<head>Hi there</head>");
$p->eof;

$p->parse("\xFE\xFF<head>Hi there</head>");
$p->eof;

$p->parse("\0\0\xFF\xFE<head>Hi there</head>");
$p->eof;

$p->parse("\xFE\xFF\0\0<head>Hi there</head>");
$p->eof;

for (@warn) {
    s/line (\d+)/line ##/g;
}

is(join("", @warn), <<EOT);
Parsing of undecoded UTF-8 will give garbage when decoding entities at $0 line ##.
Parsing of undecoded UTF-8 will give garbage when decoding entities at $0 line ##.
Parsing of undecoded UTF-16 at $0 line ##.
Parsing of undecoded UTF-16 at $0 line ##.
Parsing of undecoded UTF-32 at $0 line ##.
Parsing of undecoded UTF-32 at $0 line ##.
EOT

@warn = ();

$p = HTML::Parser->new(
  api_version => 3,
  start_h => [\@parsed, 'tag'],
);

$p->parse("\xEF\xBB\xBF<head>Hi there</head>");
$p->eof;
ok(!@warn);
}