@@ -45,6 +45,7 @@ typedef struct {
45
45
size_t current_input_length ;
46
46
size_t current_total_offset ;
47
47
dom_line_column_cache cache_tokenizer ;
48
+ bool html_no_implied ;
48
49
} dom_lexbor_libxml2_bridge_application_data ;
49
50
50
51
typedef struct {
@@ -252,6 +253,12 @@ static void dom_lexbor_libxml2_bridge_tokenizer_error_reporter(void *application
252
253
static void dom_lexbor_libxml2_bridge_tree_error_reporter (void * application_data_voidptr , lxb_html_tree_error_t * error , size_t line , size_t column , size_t len )
253
254
{
254
255
dom_lexbor_libxml2_bridge_application_data * application_data = application_data_voidptr ;
256
+
257
+ if (line == 1 && application_data -> html_no_implied && error -> id == LXB_HTML_RULES_ERROR_UNTOININMO ) {
258
+ /* For no implied mode, we want to mimick libxml's behaviour of not reporting an error for a lacking doctype. */
259
+ return ;
260
+ }
261
+
255
262
if (UNEXPECTED (len <= 1 )) {
256
263
/* Possible with EOF, or single-character tokens, don't use a range in the error display in this case */
257
264
php_libxml_pretend_ctx_error_ex (line , column , "tree error %s in %s, line: %zu, column: %zu\n" , dom_lexbor_tree_error_code_to_string (error -> id ), application_data -> input_name , line , column );
@@ -549,6 +556,7 @@ PHP_METHOD(DOM_HTMLDocument, createFromString)
549
556
dom_lexbor_libxml2_bridge_application_data application_data ;
550
557
application_data .input_name = "Entity" ;
551
558
application_data .current_total_offset = 0 ;
559
+ application_data .html_no_implied = options & HTML_PARSE_NOIMPLIED ;
552
560
dom_reset_line_column_cache (& application_data .cache_tokenizer );
553
561
lexbor_libxml2_bridge_parse_context ctx ;
554
562
lexbor_libxml2_bridge_parse_context_init (& ctx );
@@ -660,6 +668,7 @@ PHP_METHOD(DOM_HTMLDocument, createFromFile)
660
668
dom_lexbor_libxml2_bridge_application_data application_data ;
661
669
application_data .input_name = filename ;
662
670
application_data .current_total_offset = 0 ;
671
+ application_data .html_no_implied = options & HTML_PARSE_NOIMPLIED ;
663
672
dom_reset_line_column_cache (& application_data .cache_tokenizer );
664
673
lexbor_libxml2_bridge_parse_context ctx ;
665
674
lexbor_libxml2_bridge_parse_context_init (& ctx );
0 commit comments