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

@ -27,6 +27,8 @@ static void fuxmlwr_destroy(pTHX_ fuxmlwr *wr) {
static void fuxmlwr_escape(pTHX_ fuxmlwr *wr, SV *sv) {
if (SvROK(sv) && !SvAMAGIC(sv)) fu_confess("Invalid attempt to output bare reference");
STRLEN len;
const unsigned char *str = (unsigned char *)SvPV_const(sv, len);
const unsigned char *tmp, *end = str + len;
@ -96,7 +98,7 @@ static void fuxmlwr_tag(pTHX_ fuxmlwr *wr, I32 ax, I32 offset, I32 argc, int sel
val = ST(offset);
offset++;
// Don't even try to stringify other arguments; non-string keys are always a bug.
// Don't even try to stringify attribute names; non-string keys are always a bug.
if (!SvPOK(key)) fu_confess("Non-string attribute");
keys = SvPVX(key);