-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Add HTML5/UTF-8 spec-compliant text decoder. #14927
base: master
Are you sure you want to change the base?
Conversation
This is a first draft implementing a spec-compliant HTML5 text decoder. Unlike the other HTML/XML decoding functions, this is non-configurable.
My 2cents. The function name is bad and too long. It has some commonalities with Anyway, I suggest to discuss this on the internal mailing list. In any case this will require an RFC. |
thank you @alecpl - for now this is intended to support an RFC once I can get one written up. it's very specific right now and I assume the name will change, but the specifics are there to clarify what it does and doesn't do. in the RFC, I will draw a distinction in usability over the DOM solution, which would require additional setup that is easy to overlook, such as duplicating the string inside additional HTML inside the right tag or attribute, only then to parse the structure again as a DOM, then to extract the original string through DOM methods. for the same reason that |
You can reuse the internals of the tokenizer and parser in ext-dom, otherwise we duplicate part of parsing logic which doesn't seem optimal. |
``` In file included from /home/runner/work/php-src/php-src/Zend/zend.h:27, from /home/runner/work/php-src/php-src/main/php.h:31, from /home/runner/work/php-src/php-src/ext/standard/html.c:37: /home/runner/work/php-src/php-src/ext/standard/html.c: In function ‘zif_decode_html’: /home/runner/work/php-src/php-src/Zend/zend_types.h:1066:36: error: ‘matched_byte_length’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 1066 | Z_TYPE_INFO_P(__z) = IS_LONG; \ | ^ /home/runner/work/php-src/php-src/ext/standard/html.c:1648:11: note: ‘matched_byte_length’ was declared here 1648 | zval *matched_byte_length; | ^~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ```
You should not edit the arginfo files directly because it's a generated file. |
thank you @nielsdos! I'm reading all sorts of Zend docs trying to figure this out. I will attempt to follow your instructions. thankfully I found the silly mistakes in my decoder logic. one thing I'm wanting to do with this is compare it against |
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
This is a first draft implementing a spec-compliant HTML5 text decoder. Unlike the other HTML/XML decoding functions, this is non-configurable.
It is assumed that the input represents the full attribute value or text node, and any invocations with a substring of the full value may decode improperly at the end of the string.
The upsides are
This PR only currently demonstrates the step function which decodes a character reference at the given string cursor. A full decoder should only involve a loop, code to find the next
&
, and a string builder.Performance
I've tested different methods of decoding raw content as well as normative HTML document.
Testing was performed on an EPYC 2.0 GHz server with 64 GB ram.
html_entity_decode( …, ENT_HTML5 | ENT_QUOTES | ENT_SUBSTITUTE )
decode_html()
\DOM\HTMLDocument
WP_HTML_Decoder
Questions
offset
, mustlength
always be present? the character reference decoder should still know where the span of text comprising the attribute or text node ends, otherwise it might assume that the end is at the end of the full string, not just the local region (e.g. within an attribute)