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:
Yorhel 2025-06-02 09:00:04 +02:00
parent f8cd8a6d8c
commit a43dc70ff9
2 changed files with 20 additions and 1 deletions

View file

@ -65,4 +65,21 @@ sub t {
is fragment { t 'arg' }, '<div attr1="arg"><span>ab&quot; &lt; c &amp;&lt; 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 { {} };