summaryrefslogtreecommitdiff
path: root/lib/TUWF/XML.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2011-01-11 15:19:36 +0100
committerYorhel <git@yorhel.nl>2011-01-11 15:19:36 +0100
commit732b38ca27d3e70c43cc4591675021a53815321b (patch)
tree865c1cdd34d5f51b788c490528e03b26ebb7b85b /lib/TUWF/XML.pm
parentf3b328f9cb528b234f208ad6cbe9b742f303f05b (diff)
TUWF::XML: carp or croak on some common errors
This should make debugging a lot easier
Diffstat (limited to 'lib/TUWF/XML.pm')
-rw-r--r--lib/TUWF/XML.pm15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/TUWF/XML.pm b/lib/TUWF/XML.pm
index 5661cc1..a36c85b 100644
--- a/lib/TUWF/XML.pm
+++ b/lib/TUWF/XML.pm
@@ -7,6 +7,7 @@ package TUWF::XML;
use strict;
use warnings;
use Exporter 'import';
+use Carp 'carp', 'croak';
our(@EXPORT_OK, %EXPORT_TAGS, @htmltags, @htmlexport, @xmlexport, @htmlbool, $OBJ);
@@ -59,7 +60,10 @@ sub new {
# (not a method)
sub xml_escape {
local $_ = shift;
- return '' if !$_ && $_ ne '0';
+ if(!defined $_) {
+ carp "Attempting to XML-escape an undefined value";
+ return '';
+ }
s/&/&amp;/g;
s/</&lt;/g;
s/>/&gt;/g;
@@ -95,11 +99,16 @@ sub _tag {
my $s = shift;
my $indirect = shift; # called as tag() or as generated html function?
my $name = shift;
- $name =~ y/A-Z/a-z/ if $indirect;
+ croak "Invalid XML tag name" if !$name || $name =~ /^(xml|[^a-z])/i || $name =~ / /;
+ $name =~ y/A-Z/a-z/ if $indirect;
my $t = $s->{pretty} ? "\n".(' 'x(@{$s->{stack}}*$s->{pretty})) : '';
$t .= '<'.$name;
- $t .= ' '.(shift).'="'.xml_escape(shift).'"' while @_ > 1;
+ while(@_ > 1) {
+ my $attr = shift;
+ croak "Invalid XML attribute name" if !$attr || $attr =~ /^(xml|[^a-z])/i || $attr =~ / /;
+ $t .= qq{ $attr="}.xml_escape(shift).'"';
+ }
push @_, undef if $indirect && !@_ && grep $name eq $_, @htmlbool;