| 1 | 2 | 3 |

, but possibly between
and
# Example (Reverse 'Debian' in all text) : # lynx -dump -source -raw http://www/debian.org > /tmp/a.txt # ./htextsub '$_ =~ s/Debian/Naibed/gi' /tmp/a.txt use strict; use warnings; use HTML::Parser (); my $code = shift || usage(); $code = 'sub edit_print { local $_ = shift; ' . $code . '; print }'; #print $code; eval $code; die $@ if $@; my $p = HTML::Parser->new( unbroken_text => 1, default_h => [sub { print @_; }, "text"], text_h => [\&edit_print, "text"], ); my $file = shift || usage(); $p->parse_file($file) || die "Can't open file $file: $!\n"; sub usage { my $progname = $0; $progname =~ s,^.*/,,; die "Usage: $prognameR\xC3\xA9ductions jusqu'à -70%.
Réductions jusqu'à -70%."
);
$p->eof;
is($parsed[2][1], "R\xC3\xA9ductions jusqu'\xC3\xA0 -70%.");
is($parsed[4][1], "R\xC3\xA9ductions jusqu'\xC3\xA0 -70%.");
Makefile.PL 100644 001750 001751 3351 15253600633 14536 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86 # This Makefile.PL for HTML-Parser was generated by
# Dist::Zilla::Plugin::MakeMaker::Awesome 0.49.
# Don't edit it but the dist.ini and plugins used to construct it.
use strict;
use warnings;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "HTML parser class",
"AUTHOR" => "Gisle Aas The purpose of this table is to test how various browsers expands
HTML entities in various edge cases in order to improve compatibility
for HTML-Parser.
overflow:
3= 33=! 333=ō 3333=അ 33333=舵 333333= 3333333= 33333333= 333333333= 3333333333= 33333333333=
ref: x ÿx ࿿x x x
This table records observations of how various browsers behave with
regards to expanding entities. The term "Latin-1 entities" means named
entities that map to characters in the 0 .. 255 range. The term
"Unicode entities" means named entities that are not "Latin-1
entities".
Ho ho
<--comment->
EOT
$p->parse($doc)->eof;
#use Data::Dump; Data::Dump::dump(@expected);
for my $i (1 .. length($doc)) {
my @t;
$p->handler(default => \@t);
$p->parse(chunk($doc, $i));
# check that we got the same stuff
#diag "X:", join(":", @t);
#diag "Y:", join(":", @expected);
is(join(":", @t), join(":", @expected));
}
sub chunk {
my $str = shift;
my $size = shift || 1;
sub {
my $res = substr($str, 0, $size);
#diag "...$res";
substr($str, 0, $size) = "";
$res;
}
}
# Test croking behaviour
$p->handler(default => []);
my $error;
{
local $@;
#<<< do not let perltidy touch this
$error = $@ || 'Error' unless eval {
$p->parse(sub { die "Hi" });
1
};
#>>>
}
like($error, qr/^Hi/);
document.t 100644 001750 001751 1376 15253600633 15037 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86/t use strict;
use warnings;
use File::Spec ();
use HTML::Parser ();
use Test::More tests => 6;
my $events;
my $p
= HTML::Parser->new(default_h => [sub { $events .= "$_[0]\n"; }, "event"]);
$events = "";
$p->eof;
is($events, "start_document\nend_document\n");
$events = "";
$p->parse_file(File::Spec->devnull);
is($events, "start_document\nend_document\n");
$events = "";
$p->parse("");
$p->eof;
is($events, "start_document\nend_document\n");
$events = "";
$p->parse("");
$p->parse("");
$p->eof;
is($events, "start_document\nend_document\n");
$events = "";
$p->parse("");
$p->parse("");
$p->eof;
is($events, "start_document\nstart\nend_document\n");
$events = "";
$p->parse(" ");
$p->eof;
is($events, "start_document\nstart\ntext\nend_document\n");
entities.t 100644 001750 001751 35264 15253600633 15070 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86/t use strict;
use warnings;
use utf8;
use HTML::Entities
qw(_decode_entities decode_entities encode_entities encode_entities_numeric);
use Test::More tests => 43;
my $x = "Våre norske tegn bør æres";
decode_entities($x);
is($x, "Våre norske tegn bør æres");
encode_entities($x);
is($x, "Våre norske tegn bør æres");
decode_entities($x);
encode_entities_numeric($x);
is($x, "Våre norske tegn bør æres");
$x = "<&>\"'";
is(encode_entities($x), "<&>"'");
is(encode_entities_numeric($x), "<&>"'");
$x = "abcdef";
is(encode_entities($x, 'a-c'), "abcdef");
$x = "[24/7]\\";
is(encode_entities($x, '/'), "[24/7]\\");
is(encode_entities($x, '\\/'), "[24/7]\\");
is(encode_entities($x, '\\'), "[24/7]\");
is(encode_entities($x, ']\\'), "[24/7]\");
# https://github.com/libwww-perl/HTML-Parser/issues/44
$x = '<]$a/b\c/d$';
is(encode_entities($x, '$'), '<]$a/b\\c/d$');
is(encode_entities($x, '\\\\/'), '<]$a/b\c/d$');
is(encode_entities($x, '\\\\/$'), '<]$a/b\c/d$');
is(encode_entities($x, '<\\\\]'), '<]$a/b\c/d$');
# POSIX character classes
$x = "Entities expansion test page
ent with without dec hex hexx ref & & &&amp && && &x ref ' ' &apos&aposapos '' '' 'x ref × × ××times ×× ×× ×x ref € € &euro&euroeuro €€ €€ €x ref ♥ ♥ &hearts&heartshearts ♥♥ ♥♥ ♥x ref Results
entities2.t 100644 001750 001751 3102 15253600633 15114 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86/t use strict;
use warnings;
use utf8;
use HTML::Entities qw(_decode_entities);
use Test::More tests => 9;
{
local $@;
my $error;
#<<< do not let perltidy touch this
$error = $@ || 'Error' unless eval {
_decode_entities("<", undef);
1;
};
#>>>
like($error,
qr/^(?:Can't inline decode readonly string|Modification of a read-only value attempted)/
);
}
{
local $@;
my $error;
#<<< do not let perltidy touch this
$error = $@ || 'Error' unless eval {
my $x = "";
_decode_entities($x, $x);
1;
};
#>>>
like($error, qr/^2nd argument must be hash reference/);
}
{
local $@;
my $error;
#<<< do not let perltidy touch this
$error = $@ || 'Error' unless eval {
my $x = "";
_decode_entities($x, []);
1;
};
#>>>
like($error, qr/^2nd argument must be hash reference/);
}
my $x = "<";
_decode_entities($x, undef);
is($x, "<");
_decode_entities($x, {"lt" => "<"});
is($x, "<");
$x = "x" x 20;
my $err;
for (":", ":a", "a:", "a:a", "a:a:a", "a:::a") {
my $x = $_;
$x =~ s/:/&a;/g;
my $y = $_;
$y =~ s/:/$x/g;
_decode_entities($x, {"a" => $x});
if ($x ne $y) {
diag "Something went wrong with '$_'";
$err++;
}
}
ok(!$err);
$x = "foo bar";
_decode_entities($x, \%HTML::Entities::entity2char);
is($x, "foo\xA0bar");
$x = "foo bar";
_decode_entities($x, \%HTML::Entities::entity2char);
is($x, "foo bar");
_decode_entities($x, \%HTML::Entities::entity2char, 1);
is($x, "foo\xA0bar");
largetags.t 100644 001750 001751 1315 15253600633 15163 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86/t use strict;
use warnings;
use HTML::Parser ();
use Test::More tests => 2;
# Exercise the tokenpos buffer allocation routines by feeding it
# very large tags.
my $p = HTML::Parser->new(api_version => 3);
$p->handler(
"start" => sub {
my $tp = shift;
#diag int(@$tp), " - ", join(", ", @$tp);
is(@$tp, 2 + 26 * 6 * 4);
},
"tokenpos"
);
$p->handler(
"declaration" => sub {
my $t = shift;
#diag int(@$t), " - @$t";
is(@$t, 26 * 6 * 2 + 1);
},
"tokens"
);
$p->parse("parse("$_=1 ");
}
$p->parse(">");
$p->parse("parse("$_ -- $_ -- ");
}
$p->parse(">");
$p->eof;
parsefile.t 100644 001750 001751 2163 15253600633 15166 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86/t use strict;
use warnings;
use HTML::Parser ();
use IO::File ();
use Test::More tests => 6;
my $filename = "file$$.htm";
die "$filename is already there" if -e $filename;
{
open(my $fh, '>', $filename) || die "Can't create $filename: $!";
print {$fh} "
feature
do
don't
expand '
HTML-Parser >= 3.22, FireFox 1.5, Konqueror 3.4.3, Safari 2.0
HTML-Parser <= 3.21, MSIE 7.0 beta 2
expand Latin-1 entities that are not terminated by semicolon
HTML-Parser, FireFox 1.5, Konqueror 3.4.3, MSIE 7.0 beta 2, Safari 2.0
expand prefix of Latin-1 entities in text content
HTML-Parser >= 3.40, Konqueror 3.4.3, MSIE 7.0 beta 2
HTML-Parser <= 3.38, FireFox 1.5, Safari 2.0
expand Unicode entities that are not terminated by semicolon in text content
HTML-Parser <= 3.50, FireFox 1.5, Safari 2.0
HTML-Parser >= 3.51, Konqueror 3.4.3, MSIE 7.0 beta 2
expand Unicode entities that are not terminated by semicolon in attributes
HTML-Parser <= 3.50
HTML-Parser >= 3.51, FireFox 1.5, Konqueror 3.4.3, MSIE 7.0 beta 2, Safari 2.0
expand hex entities that are not terminated by semicolon in text content
HTML-Parser, FireFox 1.5, Konqueror 3.4.3, Safari 2.0
MSIE 7.0 beta 2
expand hex entities that are not terminated by semicolon in attributes
HTML-Parser, FireFox 1.5, Konqueror 3.4.3, MSIE 7.0 beta 2, Safari 2.0
.
HTML
# Try the callback interface
my $links = "";
my $p = HTML::LinkExtor->new(sub {
my($tag, %links) = @_;
#diag "$tag @{[%links]}";
$links .= "$tag @{[%links]}\n";
});
$p->parse($HTML); $p->eof;
ok($links =~ m|^base href http://www\.sn\.no/$|m);
ok($links =~ m|^a href link\.html$|m);
# Used to be problems when using the links method on a document with
# no links it it. This is a test to prove that it works.
$p = new HTML::LinkExtor;
$p->parse("this is a document with no links"); $p->eof;
my @links = $p->links;
is(@links, 0);
stack-realloc.t 100644 001750 001751 625 15253600633 15721 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86/t use strict;
use warnings;
use HTML::Parser ();
use Test::More tests => 1;
# HTML-Parser 3.33 and older used to core dump on this program because
# of missing SPAGAIN calls in parse() XS code. It was not prepared for
# the stack to get realloced.
$| = 1;
my $x = HTML::Parser->new(api_version => 3);
my @row;
$x->handler(end => sub { push(@row, (1) x 505); 1 }, "tagname");
$x->parse("");
pass;
unbroken-text.t 100644 001750 001751 2224 15253600633 16017 0 ustar 00olaf olaf 000000 000000 HTML-Parser-3.86/t use strict;
use warnings;
use HTML::Parser ();
use Test::More tests => 3;
my $text = "";
sub text {
my $cdata = shift() ? "CDATA" : "TEXT";
my ($offset, $line, $col, $t) = @_;
$text .= "[$cdata:$offset:$line.$col:$t]";
}
sub tag {
$text .= shift;
}
my $p = HTML::Parser->new(
unbroken_text => 1,
text_h => [\&text, "is_cdata,offset,line,column,text"],
start_h => [\&tag, "text"],
end_h => [\&tag, "text"],
);
$p->parse("foo ");
$p->parse("bar ");
$p->parse("
By default, "LIST]" is parsed as a boolean attribute, not as
part of the ALT value as was clearly intended. This is also what
Mozilla sees.
The official behaviour is enabled by enabling this attribute. If
enabled, it will cause the tag above to be reported as text
since "LIST]" is not a legal attribute name.
=item $p->unbroken_text
=item $p->unbroken_text( $bool )
By default, blocks of text are given to the text handler as soon as
possible (but the parser takes care always to break text at a
boundary between whitespace and non-whitespace so single words and
entities can always be decoded safely). This might create breaks that
make it hard to do transformations on the text. When this attribute is
enabled, blocks of text are always reported in one piece. This will
delay the text event until the following (non-text) event has been
recognized by the parser.
Note that the CNext example
This is very nice example.
EOT
#------------------------------------------------------
my @tags;
$p = HTML::Parser->new(api_version => 3);
$p->report_tags(qw(a em));
$p->ignore_tags(qw(em));
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
This is yet another very nice example.
EOT
is(join('|', @tags), 'a', 'report_tags followed by ignore_tags');
#------------------------------------------------------
@tags = ();
$p = HTML::Parser->new(api_version => 3);
$p->report_tags(qw(h1));
$p->report_tags();
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
Next example
EOT
is(join('|', @tags), 'h1|h2', 'reset report_tags filter');
#------------------------------------------------------
@tags = ();
$p = HTML::Parser->new(api_version => 3);
$p->report_tags(qw(h1 h2));
$p->ignore_tags(qw(h2));
$p->report_tags(qw(h1 h2));
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
Next example
EOT
is(join('|', @tags), 'h1', 'report_tags does not reset ignore_tags');
#------------------------------------------------------
@tags = ();
$p = HTML::Parser->new(api_version => 3);
$p->report_tags(qw(h1 h2));
$p->ignore_tags(qw(h2));
$p->report_tags();
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
Next example
EOT
is(join('|', @tags), 'h1', 'reset report_tags does no reset ignore_tags');
#------------------------------------------------------
@tags = ();
$p = HTML::Parser->new(api_version => 3);
$p->report_tags(qw(h1 h2));
$p->report_tags(qw(h3));
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
Next example
Next example
EOT
is(join('|', @tags), 'h3', 'report_tags replaces filter');
#------------------------------------------------------
@tags = ();
$p = HTML::Parser->new(api_version => 3);
$p->ignore_tags(qw(h1 h2));
$p->ignore_tags(qw(h3));
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
Next example
Next example
EOT
is(join('|', @tags), 'h1|h2', 'ignore_tags replaces filter');
#------------------------------------------------------
@tags = ();
$p = HTML::Parser->new(api_version => 3);
$p->ignore_tags(qw(h2));
$p->ignore_tags();
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
Next example
EOT
is(join('|', @tags), 'h1|h2', 'reset ignore_tags filter');
#------------------------------------------------------
@tags = ();
$p = HTML::Parser->new(api_version => 3);
$p->ignore_tags(qw(h2));
$p->report_tags(qw(h1 h2));
$p->handler(end => sub { push @tags, @_; }, 'tagname');
$p->parse(<Next example
Next example
EOT
is(join('|', @tags), 'h1', 'ignore_tags before report_tags');
#------------------------------------------------------
$p = HTML::Parser->new(api_version => 3);
$p->ignore_elements("script");
my $res = "";
$p->handler(default => sub { $res .= $_[0]; }, 'text');
$p->parse(<<'EOT')->eof;
A C D F
EOT
is($res, "A C D F\n", "ignore without