XMLWriter: Throw error when stringifying a bare reference
I can't think of a use case where Perl's default ref stringification is something you actually want when writing XML/HTML - this pretty much always points to a bug. One that I seem to be prone to making...
This commit is contained in:
parent
f8cd8a6d8c
commit
a43dc70ff9
2 changed files with 20 additions and 1 deletions
17
t/xmlwr.t
17
t/xmlwr.t
|
|
@ -65,4 +65,21 @@ sub t {
|
|||
|
||||
is fragment { t 'arg' }, '<div attr1="arg"><span>ab" < c &< d</span><span><ok🥳ay></span>🥳</div>';
|
||||
|
||||
ok !eval { fragment { tag_ 'hi', \1 } };
|
||||
like $@, qr/Invalid attempt to output bare reference/;
|
||||
|
||||
ok !eval { fragment { tag_ 'hi', {} } };
|
||||
like $@, qr/Invalid attempt to output bare reference/;
|
||||
|
||||
is fragment { tag_ 'hi', bless {}, 'XTEST1' }, '<hi>string</hi>';
|
||||
like fragment { tag_ 'hi', bless {}, 'XTEST2' }, qr{<hi>HASH\(.*\)</hi>}; # Yeah, whatever.
|
||||
like fragment { tag_ 'hi', ''.{} }, qr{<hi>HASH\(.*\)</hi>};
|
||||
|
||||
done_testing;
|
||||
|
||||
|
||||
package XTEST1;
|
||||
use overload '""' => sub { 'string' };
|
||||
|
||||
package XTEST2;
|
||||
use overload '""' => sub { {} };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue