petdance/html-lint — Issue #13: 	If Invalid character not in %HTML::Entities::char2entity set then an undefined value warning is emitted
Author: petdance
Created: 2011-12-05 23:04:50+00:00
State: open

Reported by struandonald, Oct 24, 2009

Hi,

If you run this script which includes a character not included in %HTML::Entities::char2entity then
when you try to print out the error message you get a warning about undefined values

```
use strict;
use warnings;
use utf8;
use HTML::Lint;

my $html = ' ★ ';

my $l = HTML::Lint->new();
$l->parse( $html );
foreach my $e ( $l->errors ) {
print $e->as_string . "\n";
}
```

This is the output I get:

```
Use of uninitialized value $val in substitution (s///) at
/usr/local/lib/perl5/site_perl/5.10.0/HTML/Lint/Error.pm line 112.
(:1) Invalid character \x2605 should be written as
```

I've tweaked mine with this patch:

```
--- Lint.pm 2009-10-24 16:46:02.000000000 +0100
+++ Lint_fixed.pm 2009-10-24 16:46:54.000000000 +0100
@@ -372,7 +372,7 @@
$self->gripe(
'text-use-entity',
char => sprintf( '\x%02lX', ord($bad) ),
- entity => $char2entity{ $bad },
+ entity => $char2entity{ $bad } || sprintf( '&#%d;', ord( $bad ) ),
);
}
```

which produces this output instead:

```
(:1) Invalid character \x2605 should be written as ★
```

All this is on Perl 5.10.1 with
HTML::Entities 3.63
HTML::Lint 2.06