Skip to content

Commit a0dccc0

Browse files
committed
MC-41013: Prevent errors from incorrect configurations
1 parent c1b046b commit a0dccc0

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

lib/internal/Magento/Framework/View/Element/UiComponent/Argument/Interpreter/ConfigurableObject.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,37 @@ public function evaluate(array $data)
9393
if (!isset($arguments['class'])) {
9494
throw new \InvalidArgumentException('Node "argument" with name "class" is required for this type.');
9595
}
96+
9697
$className = $arguments['class'];
9798
unset($arguments['class']);
99+
100+
$type = $this->objectManagerConfig->getInstanceType(
101+
$this->objectManagerConfig->getPreference($className)
102+
);
103+
104+
$classParents = $this->getParents($type);
105+
106+
$whitelistIntersection = array_intersect($classParents, $this->classWhitelist);
107+
108+
if (empty($whitelistIntersection)) {
109+
throw new \InvalidArgumentException(
110+
sprintf('Class argument is invalid: %s', $className)
111+
);
112+
}
98113
}
99114

100-
$this->isValid($className);
115+
$type = $this->objectManagerConfig->getInstanceType(
116+
$this->objectManagerConfig->getPreference($className)
117+
);
118+
$classParents = $this->getParents($type);
119+
120+
$deniedIntersection = array_intersect($classParents, $this->deniedClassList);
121+
122+
if (!empty($deniedIntersection)) {
123+
throw new \InvalidArgumentException(
124+
sprintf('Class argument is invalid: %s', $className)
125+
);
126+
}
101127

102128
return $this->objectManager->create($className, $arguments);
103129
}
@@ -120,30 +146,4 @@ private function getParents(string $type)
120146

121147
return $classParents;
122148
}
123-
124-
/**
125-
* Check that provided class could be evaluated like an argument.
126-
*
127-
* @param string $className
128-
* @throws \InvalidArgumentException
129-
*/
130-
private function isValid(string $className): void
131-
{
132-
$type = $this->objectManagerConfig->getInstanceType(
133-
$this->objectManagerConfig->getPreference($className)
134-
);
135-
136-
$classParents = $this->getParents($type);
137-
138-
if (!empty($classParents)) {
139-
$whitelistIntersection = array_intersect($classParents, $this->classWhitelist);
140-
$deniedIntersection = array_intersect($classParents, $this->deniedClassList);
141-
142-
if (empty($whitelistIntersection) || !empty($deniedIntersection)) {
143-
throw new \InvalidArgumentException(
144-
sprintf('Class argument is invalid: %s', $className)
145-
);
146-
}
147-
}
148-
}
149149
}

0 commit comments

Comments
 (0)