Skip to content

Commit 2ca688f

Browse files
committed
Replace uniqid() with counter in XmlDeserializationVisitor
uniqid() is just slow and not even cryptographically secure. The prefix only needs to be unique within a single XPath registerXPathNamespace() call, not globally. Replaced with simpler int counter.
1 parent 9a80b3a commit 2ca688f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/XmlDeserializationVisitor.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ final class XmlDeserializationVisitor extends AbstractVisitor implements NullAwa
5353
* @var int
5454
*/
5555
private $options;
56+
/**
57+
* @var int
58+
*/
59+
private $xpathPrefixCounter = 0;
5660

5761
public function __construct(
5862
bool $disableExternalEntities = true,
@@ -212,7 +216,7 @@ public function visitArray($data, array $type): array
212216
}
213217

214218
if (null !== $namespace) {
215-
$prefix = uniqid('ns-');
219+
$prefix = 'ns-' . $this->xpathPrefixCounter++;
216220
$data->registerXPathNamespace($prefix, $namespace);
217221
$nodes = $data->xpath(sprintf('%s:%s', $prefix, $entryName));
218222
} else {
@@ -433,7 +437,7 @@ public function visitProperty(PropertyMetadata $metadata, $data)
433437
} else {
434438
$namespaces = $data->getDocNamespaces();
435439
if (isset($namespaces[''])) {
436-
$prefix = uniqid('ns-');
440+
$prefix = 'ns-' . $this->xpathPrefixCounter++;
437441
$data->registerXPathNamespace($prefix, $namespaces['']);
438442
$nodes = $data->xpath('./' . $prefix . ':' . $name);
439443
} else {

0 commit comments

Comments
 (0)