From a5346a47dce6074e8864eaeb8c84b35026b9765f Mon Sep 17 00:00:00 2001 From: Swappp Date: Mon, 26 Jan 2009 23:49:30 +0300 Subject: [PATCH] Fix XPath parser --- XMPPHP/XMLStream.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/XMPPHP/XMLStream.php b/XMPPHP/XMLStream.php index cc30a66..ff2c1d5 100644 --- a/XMPPHP/XMLStream.php +++ b/XMPPHP/XMLStream.php @@ -558,20 +558,16 @@ class XMLStream */ public function addXPathHandler(string $xpath, string $pointer, ?string $obj = null): void { - if (preg_match_all("/\(?{[^\}]+}\)?(\/?)[^\/]+/", $xpath, $regs)) { - $ns_tags = $regs[0]; + if (preg_match_all('/\/?(\{[^\}]+\})?[^\/]+/', $xpath, $regs)) { + $tag = $regs[0]; } else { - $ns_tags = [$xpath]; + $tag = [$xpath]; } $xpath_array = []; - foreach ($ns_tags as $ns_tag) { - list($l, $r) = explode("}", $ns_tag); - if ($r != null) { - $xpart = [substr($l, 1), $r]; - } else { - $xpart = [null, $l]; - } - $xpath_array[] = $xpart; + foreach ($tag as $t) { + $t = ltrim($t, '/'); + preg_match('/(\{([^\}]+)\})?(.*)/', $t, $regs); + $xpath_array[] = [$regs[2], $regs[3]]; } $this->xpathhandlers[] = [$xpath_array, $pointer, $obj]; }