Skip to content

Commit 8dc799a

Browse files
committed
Port XML_GetCurrentByteIndex to public APIs
This is necessary to avoid a deprecation break in libxml2 2.14.x.
1 parent 1e5f46f commit 8dc799a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ext/xml/compat.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,21 @@ XML_GetCurrentColumnNumber(XML_Parser parser)
705705
PHP_XML_API int
706706
XML_GetCurrentByteIndex(XML_Parser parser)
707707
{
708-
return parser->parser->input->consumed +
709-
(parser->parser->input->cur - parser->parser->input->base);
708+
/* We have to temporarily disable the encoder to satisfy the note from the manual:
709+
* "This function returns byte index according to UTF-8 encoded text disregarding if input is in another encoding."
710+
* Although that should probably be corrected at one point? (TODO) */
711+
xmlCharEncodingHandlerPtr encoder = NULL;
712+
xmlParserInputPtr input = parser->parser->input;
713+
if (input->buf) {
714+
encoder = input->buf->encoder;
715+
input->buf->encoder = NULL;
716+
}
717+
long result = xmlByteConsumed(parser->parser);
718+
if (encoder) {
719+
input->buf->encoder = encoder;
720+
}
721+
/* TODO: at one point this should return long probably to make sure that files greater than 2 GiB are handled correctly. */
722+
return (int) result;
710723
}
711724

712725
PHP_XML_API int

0 commit comments

Comments
 (0)