@@ -451,13 +451,13 @@ XML_ParserCreate_MM(const XML_Char *encoding, const XML_Memory_Handling_Suite *m
451
451
}
452
452
453
453
php_libxml_sanitize_parse_ctxt_options (parser -> parser );
454
- xmlCtxtUseOptions (parser -> parser , XML_PARSE_OLDSAX );
454
+ xmlCtxtUseOptions (parser -> parser , XML_PARSE_OLDSAX | XML_PARSE_NOENT );
455
455
456
- parser -> parser -> replaceEntities = 1 ;
457
456
parser -> parser -> wellFormed = 0 ;
458
457
if (sep != NULL ) {
458
+ /* Note: sax2 flag will be set due to the magic number in `initialized` in php_xml_compat_handlers */
459
+ ZEND_ASSERT (parser -> parser -> sax -> initialized == XML_SAX2_MAGIC );
459
460
parser -> use_namespace = 1 ;
460
- parser -> parser -> sax2 = 1 ;
461
461
parser -> _ns_separator = xmlStrdup (sep );
462
462
} else {
463
463
/* Reset flag as XML_SAX2_MAGIC is needed for xmlCreatePushParserCtxt
@@ -543,10 +543,14 @@ XML_SetEndNamespaceDeclHandler(XML_Parser parser, XML_EndNamespaceDeclHandler en
543
543
PHP_XML_API int
544
544
XML_Parse (XML_Parser parser , const XML_Char * data , int data_len , int is_final )
545
545
{
546
- int error ;
546
+ int error = xmlParseChunk ( parser -> parser , ( char * ) data , data_len , is_final ) ;
547
547
548
- error = xmlParseChunk (parser -> parser , (char * ) data , data_len , is_final );
549
- return !error && parser -> parser -> lastError .level <= XML_ERR_WARNING ;
548
+ if (!error ) {
549
+ const xmlError * error_data = xmlCtxtGetLastError (parser -> parser );
550
+ return !error_data || error_data -> level <= XML_ERR_WARNING ;
551
+ }
552
+
553
+ return 0 ;
550
554
}
551
555
552
556
PHP_XML_API int
@@ -685,8 +689,21 @@ XML_GetCurrentColumnNumber(XML_Parser parser)
685
689
PHP_XML_API int
686
690
XML_GetCurrentByteIndex (XML_Parser parser )
687
691
{
688
- return parser -> parser -> input -> consumed +
689
- (parser -> parser -> input -> cur - parser -> parser -> input -> base );
692
+ /* We have to temporarily disable the encoder to satisfy the note from the manual:
693
+ * "This function returns byte index according to UTF-8 encoded text disregarding if input is in another encoding."
694
+ * Although that should probably be corrected at one point? (TODO) */
695
+ xmlCharEncodingHandlerPtr encoder = NULL ;
696
+ xmlParserInputPtr input = parser -> parser -> input ;
697
+ if (input -> buf ) {
698
+ encoder = input -> buf -> encoder ;
699
+ input -> buf -> encoder = NULL ;
700
+ }
701
+ long result = xmlByteConsumed (parser -> parser );
702
+ if (encoder ) {
703
+ input -> buf -> encoder = encoder ;
704
+ }
705
+ /* TODO: at one point this should return long probably to make sure that files greater than 2 GiB are handled correctly. */
706
+ return (int ) result ;
690
707
}
691
708
692
709
PHP_XML_API int
0 commit comments