Skip to content

Implement LIBXML_NOXMLDECL #11794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Jul 25, 2023

Fixes GH-11792.

Marking as a draft because I need to review it myself and double check if I messed up. OK now
Targeting master since this is on the border of new feature vs bugfix.

Verified

This commit was signed with the committer’s verified signature.
bukka Jakub Zelenka
Fixes phpGH-11792.
@nielsdos nielsdos marked this pull request as ready for review July 25, 2023 21:42
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Some comments as I'm confused and also what is LIBXML_NOXMLDECL meant to do?

If this is in master maybe we could add a new constant that has some extra underscores to make the constant easier to read and more descriptive and alias that one?

xmlSaveNoEmptyTags = 1;
}
saveempty = xmlSaveNoEmptyTags;
xmlSaveNoEmptyTags = !!(options & LIBXML_SAVE_NOEMPTYTAG);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
xmlSaveNoEmptyTags = !!(options & LIBXML_SAVE_NOEMPTYTAG);
xmlSaveNoEmptyTags = (options & LIBXML_SAVE_NOEMPTYTAG);

I'm confused by the double !! here

Copy link
Member Author

Choose a reason for hiding this comment

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

We must put 1 in xmlSaveNoEmptyTags is LIBXML_SAVE_NOEMPTYTAG is set in options. (options & LIBXML_SAVE_NOEMPTYTAG) does not equal 1 because LIBXML_SAVE_NOEMPTYTAG is not 1. By using !! the value is converted to a bool basically.
I can change it to a ternary (options & LIBXML_SAVE_NOEMPTYTAG) ? 1 : 0 though.

mem = (xmlChar*) xmlBufferContent(buf);
if (!mem) {
xmlBufferFree(buf);
xmlSaveNoEmptyTags = saveempty;
Copy link
Member

Choose a reason for hiding this comment

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

Is xmlSaveNoEmptyTags a global libxml2 variable? Because that code makes no sense otherwise

So maybe add some comment about this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is xmlSaveNoEmptyTags a global libxml2 variable?

Yes

So maybe add some comment about this?

Will do

dom_object *intern, *nodeobj;
int size, format, saveempty = 0;
int size, format, saveempty;
Copy link
Member

Choose a reason for hiding this comment

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

Is that saveempty basically a bool ? (also maybe rename it because it's not very descriptive ...)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's used to store the old value of that libxml2 global. That global is an int so I prefer to keep the same type (also for forwards compatibility, you never know they add some extra flags in there 🤷).
I'll change the name though.

Copy link
Member Author

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

I'm confused and also what is LIBXML_NOXMLDECL meant to do?

NO XML DECL: No XML declaration
It omits the declaration from the output of calling saveXML().

If this is in master maybe we could add a new constant that has some extra underscores to make the constant easier to read and more descriptive and alias that one?

Unfortunately, for whatever reason, the constants are written without underscore https://www.php.net/manual/en/libxml.constants.php 🙄
I'm not going to change that here though...

dom_object *intern, *nodeobj;
int size, format, saveempty = 0;
int size, format, saveempty;
Copy link
Member Author

Choose a reason for hiding this comment

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

It's used to store the old value of that libxml2 global. That global is an int so I prefer to keep the same type (also for forwards compatibility, you never know they add some extra flags in there 🤷).
I'll change the name though.

xmlSaveNoEmptyTags = 1;
}
saveempty = xmlSaveNoEmptyTags;
xmlSaveNoEmptyTags = !!(options & LIBXML_SAVE_NOEMPTYTAG);
Copy link
Member Author

Choose a reason for hiding this comment

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

We must put 1 in xmlSaveNoEmptyTags is LIBXML_SAVE_NOEMPTYTAG is set in options. (options & LIBXML_SAVE_NOEMPTYTAG) does not equal 1 because LIBXML_SAVE_NOEMPTYTAG is not 1. By using !! the value is converted to a bool basically.
I can change it to a ternary (options & LIBXML_SAVE_NOEMPTYTAG) ? 1 : 0 though.

mem = (xmlChar*) xmlBufferContent(buf);
if (!mem) {
xmlBufferFree(buf);
xmlSaveNoEmptyTags = saveempty;
Copy link
Member Author

Choose a reason for hiding this comment

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

Is xmlSaveNoEmptyTags a global libxml2 variable?

Yes

So maybe add some comment about this?

Will do

@Girgias
Copy link
Member

Girgias commented Jul 26, 2023

Thanks for the explanations, looks good to me now.

@nielsdos nielsdos closed this in 4bee574 Jul 26, 2023
jorgsowa pushed a commit to jorgsowa/php-src that referenced this pull request Aug 16, 2023
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.

LIBXML_NOXMLDECL is not implemented or broken
2 participants