Skip to content

EspoCRM – Open Source CRM Application

fix link name validations

Yuri Kuznetsov889a19b9bdac
diff --git a/application/Espo/Tools/EntityManager/NameUtil.php b/application/Espo/Tools/EntityManager/NameUtil.php
index 8e0e720184..8bbad8d566 100644
--- a/application/Espo/Tools/EntityManager/NameUtil.php
+++ b/application/Espo/Tools/EntityManager/NameUtil.php
@@ -29,6 +29,7 @@
namespace Espo\Tools\EntityManager;
+use Espo\Core\Exceptions\Error;
use Espo\Core\Name\Field;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
@@ -379,4 +380,20 @@ class NameUtil
{
return (bool) $this->metadata->get("entityDefs.$entityType.links.$name");
}
+
+ /**
+ * @since 9.2.4
+ */
+ public function linkNameIsBad(string $name): bool
+ {
+ if ($name === '') {
+ return true;
+ }
+
+ if (preg_match('/[^a-z]/', $name[0])) {
+ return true;
+ }
+
+ return $this->nameIsBad(ucfirst($name));
+ }
}
diff --git a/application/Espo/Tools/LinkManager/LinkManager.php b/application/Espo/Tools/LinkManager/LinkManager.php
index 59f7ffa81f..53dca356d4 100644
--- a/application/Espo/Tools/LinkManager/LinkManager.php
+++ b/application/Espo/Tools/LinkManager/LinkManager.php
@@ -139,8 +139,11 @@ class LinkManager
throw new Error("Relation name is too long.");
}
- if (preg_match('/[^a-z]/', $relationName[0])) {
- throw new Error("Relation name should start with a lower case letter.");
+ if ($this->nameUtil->linkNameIsBad($relationName)) {
+ $message = "Relation name should contain only letters and numbers, " .
+ "start with a lower case letter.";
+
+ throw new Error($message);
}
if ($this->metadata->get(['scopes', ucfirst($relationName)])) {
@@ -180,6 +183,13 @@ class LinkManager
throw new Error("Link name is too long.");
}
+ if ($this->nameUtil->linkNameIsBad($link) || $this->nameUtil->linkNameIsBad($linkForeign)) {
+ $message = "Link name should contain only letters and numbers, " .
+ "start with a lower case letter.";
+
+ throw new Error($message);
+ }
+
if (preg_match('/[^a-z]/', $link[0])) {
throw new Error("Link name should start with a lower case letter.");
}