From 9287218831d8cf6034e03eef899f5d8e36bb2e18 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 14 Aug 2024 15:38:46 +0200 Subject: add simplexml_load_string() with better error reporting --- it.class | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/it.class b/it.class index a40b6d1..537984d 100644 --- a/it.class +++ b/it.class @@ -1404,4 +1404,23 @@ static function utf8_encode($latin1) return UConverter::transcode($latin1, 'UTF8', 'ISO-8859-1'); } +/** + * Parse xml and put any offending input into error report + */ +static function simplexml_load_string($data, $class_name = null, $options = 0) +{ + $oldsetting = libxml_use_internal_errors(true); + + if (($result = simplexml_load_string($data, $class_name, $options)) === false) + { + $titles = it::map('trim($v->message) . " at line $v->line col $v->column"', libxml_get_errors()); + it::error('title' => $titles[0], ['body' => join("\n", $titles) . "\n\n$data"]); + libxml_clear_errors(); + } + + libxml_use_internal_errors($oldsetting); + + return $result; +} + } -- cgit v1.2.3