From 8b459295f2975cbe28d28be6c91818b7857eb118 Mon Sep 17 00:00:00 2001 From: Nicholas Finestead Date: Thu, 8 May 2025 22:26:57 -0500 Subject: [PATCH 1/3] Added validation and substitution for library aliases, need to test --- src/robot/libraries/BuiltIn.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/robot/libraries/BuiltIn.py b/src/robot/libraries/BuiltIn.py index 50bd99f131e..63e373f9a35 100644 --- a/src/robot/libraries/BuiltIn.py +++ b/src/robot/libraries/BuiltIn.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys import difflib import re import time @@ -3781,6 +3782,39 @@ def evaluate(self, expression, modules=None, namespace=None): evaluation namespace. It needed to be taken into use explicitly like ``modules=rootmod, rootmod.submod``. """ + + """ + If Libraries are aliased when imported, substitute alias for actual library + This is so the correct library can be passed to the python execution + The first for loop is to ensure there are no ambiguous substitutions + The second executes the substitutions for any assumed object dereference + operations + Currently this will execute the substitution inside a string + Example: + Library foo AS BAR + Evaluate BAR.baz() --> Evaluate foo.baz() + + Library foo AS BAR + Evaluate BAR.BAR.baz() --> Evaluate foo.BAR.baz() + """ + libraries = self._namespace._kw_store.libraries + for library in libraries.values(): + for name, module_obj in libraries.items(): + if name != library.name and ( + module_obj.real_name == library.name or + module_obj.real_name == library.real_name): + raise DataError("Evaluate Expression failed: " + f"Ambiguous aliases with Library '{name}' " + f"As '{module_obj.real_name}' and Library " + f"'{library.name}' As '{library.real_name}'") + for library in libraries.values(): + if library.name != library.real_name: + escaped_name = re.escape(library.name) + search_regex = re.compile(r'(? Date: Thu, 8 May 2025 22:36:47 -0500 Subject: [PATCH 2/3] Cleaned up trailing whitespace --- src/robot/libraries/BuiltIn.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/robot/libraries/BuiltIn.py b/src/robot/libraries/BuiltIn.py index 63e373f9a35..c0030d229ea 100644 --- a/src/robot/libraries/BuiltIn.py +++ b/src/robot/libraries/BuiltIn.py @@ -3793,7 +3793,7 @@ def evaluate(self, expression, modules=None, namespace=None): Example: Library foo AS BAR Evaluate BAR.baz() --> Evaluate foo.baz() - + Library foo AS BAR Evaluate BAR.BAR.baz() --> Evaluate foo.BAR.baz() """ @@ -3801,7 +3801,7 @@ def evaluate(self, expression, modules=None, namespace=None): for library in libraries.values(): for name, module_obj in libraries.items(): if name != library.name and ( - module_obj.real_name == library.name or + module_obj.real_name == library.name or module_obj.real_name == library.real_name): raise DataError("Evaluate Expression failed: " f"Ambiguous aliases with Library '{name}' " @@ -3812,7 +3812,7 @@ def evaluate(self, expression, modules=None, namespace=None): escaped_name = re.escape(library.name) search_regex = re.compile(r'(? Date: Thu, 8 May 2025 22:38:53 -0500 Subject: [PATCH 3/3] Removed unneeded import --- src/robot/libraries/BuiltIn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/robot/libraries/BuiltIn.py b/src/robot/libraries/BuiltIn.py index c0030d229ea..e2286f92fa0 100644 --- a/src/robot/libraries/BuiltIn.py +++ b/src/robot/libraries/BuiltIn.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import difflib import re import time