Skip to content

ext/xmlwriter: report the right argument number for an invalid name in method calls - #24137

Open
lacatoire wants to merge 1 commit into
php:masterfrom
lacatoire:fix/xmlwriter-oop-arg-num
Open

lacatoire wants to merge 1 commit into
php:masterfrom
lacatoire:fix/xmlwriter-oop-arg-num

Conversation

@lacatoire

Copy link
Copy Markdown
Member

XMLW_NAME_CHK hardcodes the procedural argument number, so the XMLWriter method aliases report the wrong one:

$w = new XMLWriter();
$w->openMemory();
$w->startElement('bad name');
// before: Argument #2 must be a valid element name, "bad name" given
// after:  Argument #1 ($name) must be a valid element name, "bad name" given

The macro now shifts the number by one when the call has a $this. Procedural numbers are unchanged. The new test covers the 16 affected methods and their procedural counterparts.

…n method calls

XMLW_NAME_CHK hardcodes the procedural argument number, but the same
implementations back the XMLWriter method aliases, which have no writer
parameter. Shift the number by one when the call has a $this.
#define XMLW_NAME_CHK(__arg_no, __subject) \
if (xmlValidateName((xmlChar *) name, 0) != 0) { \
zend_argument_value_error(__arg_no, "must be a valid %s, \"%s\" given", __subject, name); \
zend_argument_value_error(getThis() != NULL ? (__arg_no) - 1 : (__arg_no), "must be a valid %s, \"%s\" given", __subject, name); \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use hasThis() instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants