Subject: | double quotes in attributes can in some cases run into problems. |
Good evening,
my name is Alberto Innocenti [ainnocenti at cnainformatica dot it].
I thank you for the creation and maintenance of the module HTML::Mail;
i find it very useful and my company is using it with success in a
production environment.
i have modified it, the following are the details.
module version: HTML-Mail-0.11
perl version:
tiche:/usr/lib/perl5/site_perl/5.8.7 >perl -v
This is perl, v5.8.7 built for x86_64-linux-thread-multi
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2005, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
operating system details:
tiche:/usr/lib/perl5/site_perl/5.8.7 >uname -a
Linux tiche 2.6.13-15.8-smp #1 SMP Tue Feb 7 11:07:24 UTC 2006 x86_64
x86_64 x86_64 GNU/Linux
the subject of my modification is that
when the module creates the HTML attributes it always uses the double
quote for them,
this can run into problems in some cases, for example:
original HTML: [...] style='font-size:20.0pt;font-family:"Agency
FB","sans-serif";color:black', [...]
was encoded as: [...] style="font-size:20.0pt;font-family:"Agency
FB","sans-serif";color:black", [...]
, creating in such way an incorrect HTML.
The quick solution that i have found is to check with a regex whether
the attribute content
matches the double quotes , in such case, i use single quote for quoting
the attribute.
these are the lines of the original module:
line 243: $$content .= qq/ $_="$attr->{$_}"/ for (@$attrseq);
line 247: $$content .= qq/ $k="$v"/;
i have changed in these:
line 243: if ($attr->{$_} =~ /"/) {
line 243: $$content .= qq/ $_='$attr->{$_}'/;
line 243: } else {
line 243: $$content .= qq/ $_="$attr->{$_}"/;
line 243: }
line 247: if ($v =~ /"/) {
line 247: $$content .= qq/ $k='$v'/;
line 247: } else {
line 247: $$content .= qq/ $k="$v"/;
line 247: }
Attached is my patch file, generated with the command:
diff –crB HTML/Mail.pm HTML2/Mail.pm
Regards.
Alberto Innocenti.
Subject: | html-mail-0.11-lky.patch |
*** HTML/Mail.pm Tue Jan 25 18:39:06 2011
--- HTML2/Mail.pm Tue Jan 25 19:32:50 2011
***************
*** 240,250 ****
$$content .= "<$tag";
if ($attrseq && @$attrseq) {
! $$content .= qq/ $_="$attr->{$_}"/ for (@$attrseq);
}
else {
while (my ($k, $v) = each(%$attr)) {
! $$content .= qq/ $k="$v"/;
}
}
$$content .= " /" if $empty;
--- 240,260 ----
$$content .= "<$tag";
if ($attrseq && @$attrseq) {
! for (@$attrseq) {
! if ($attr->{$_} =~ /"/) {
! $$content .= qq/ $_='$attr->{$_}'/;
! } else {
! $$content .= qq/ $_="$attr->{$_}"/;
! }
! }
}
else {
while (my ($k, $v) = each(%$attr)) {
! if ($v =~ /"/) {
! $$content .= qq/ $k='$v'/;
! } else {
! $$content .= qq/ $k="$v"/;
! }
}
}
$$content .= " /" if $empty;