diff --git a/src/PhpPact/Xml/XmlElement.php b/src/PhpPact/Xml/XmlElement.php index 9f3d10d1..bed57158 100644 --- a/src/PhpPact/Xml/XmlElement.php +++ b/src/PhpPact/Xml/XmlElement.php @@ -34,7 +34,10 @@ public function __construct(callable ...$options) public function setName(string $name): self { - $this->name = preg_replace('/(^[0-9]+|[^a-zA-Z0-9\-\_\:]+)/', '', $name); + if (preg_match('/^[0-9]+|[^a-zA-Z0-9\-\_\:]+/', $name) !== 0) { + throw new InvalidXmlElementException("Xml element's name is invalid"); + } + $this->name = $name; return $this; }