From 98acb8f04f4e1abf6be9f8ee5ef1f1a9d92ba12b Mon Sep 17 00:00:00 2001 From: memsharded Date: Thu, 29 Feb 2024 11:10:58 +0100 Subject: [PATCH 1/2] fix conf evaluation types --- conans/model/conf.py | 4 +++- .../configuration/conf/test_conf.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/conans/model/conf.py b/conans/model/conf.py index b736dfd3990..984eeec0d9a 100644 --- a/conans/model/conf.py +++ b/conans/model/conf.py @@ -1,4 +1,6 @@ +import collections import copy +import numbers import re import os import fnmatch @@ -657,7 +659,7 @@ def _get_evaluated_value(__v): try: # Isolated eval parsed_value = eval(__v) # This destroys Windows path strings with backslash - if isinstance(parsed_value, str): # xxx:xxx = "my string" + if not isinstance(numbers.Number, collections.Collection): # If it is quoted string we respect it as-is parsed_value = __v.strip() except: diff --git a/conans/test/integration/configuration/conf/test_conf.py b/conans/test/integration/configuration/conf/test_conf.py index 5a4ee37d7ae..8b293b35a54 100644 --- a/conans/test/integration/configuration/conf/test_conf.py +++ b/conans/test/integration/configuration/conf/test_conf.py @@ -396,3 +396,21 @@ def generate(self): assert "dep/0.1: user.myteam:myconf: ['root_value', 'value1']" in c.out # The pkg/0.1 output should be non-modified assert "pkg/0.1: user.myteam:myconf: ['root_value']" in c.out + + +def test_especial_strings_fail(): + # https://github.com/conan-io/conan/issues/15777 + c = TestClient() + global_conf = textwrap.dedent(""" + user.mycompany:myfile = re + user.mycompany:myother = fnmatch + user.mycompany:myfunct = re.search + user.mycompany:mydict = {1: 're', 2: 'fnmatch'} + """) + save(c.cache.new_config_path, global_conf) + c.run("config show *") + print(c.out) + assert "user.mycompany:myfile: re" in c.out + assert "user.mycompany:myother: fnmatch" in c.out + assert "user.mycompany:myfunct: re.search" in c.out + assert "user.mycompany:mydict: {1: 're', 2: 'fnmatch'}" in c.out From b128cded1fa419d1926063f37e608ab0e3cdb3bf Mon Sep 17 00:00:00 2001 From: memsharded Date: Thu, 29 Feb 2024 15:45:19 +0100 Subject: [PATCH 2/2] fix test --- conans/model/conf.py | 19 +++++++++---------- .../configuration/conf/test_conf.py | 1 - 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/conans/model/conf.py b/conans/model/conf.py index 984eeec0d9a..8174f963f8d 100644 --- a/conans/model/conf.py +++ b/conans/model/conf.py @@ -1,4 +1,3 @@ -import collections import copy import numbers import re @@ -652,20 +651,20 @@ def serialize(self): return result @staticmethod - def _get_evaluated_value(__v): + def _get_evaluated_value(_v): """ Function to avoid eval() catching local variables """ try: - # Isolated eval - parsed_value = eval(__v) # This destroys Windows path strings with backslash - if not isinstance(numbers.Number, collections.Collection): + value = eval(_v) # This destroys Windows path strings with backslash + except: # It means eval() failed because of a string without quotes + value = _v.strip() + else: + if not isinstance(value, (numbers.Number, bool, dict, list, set, tuple)) \ + and value is not None: # If it is quoted string we respect it as-is - parsed_value = __v.strip() - except: - # It means eval() failed because of a string without quotes - parsed_value = __v.strip() - return parsed_value + value = _v.strip() + return value def loads(self, text, profile=False): self._pattern_confs = {} diff --git a/conans/test/integration/configuration/conf/test_conf.py b/conans/test/integration/configuration/conf/test_conf.py index 8b293b35a54..61cb4ca95b3 100644 --- a/conans/test/integration/configuration/conf/test_conf.py +++ b/conans/test/integration/configuration/conf/test_conf.py @@ -409,7 +409,6 @@ def test_especial_strings_fail(): """) save(c.cache.new_config_path, global_conf) c.run("config show *") - print(c.out) assert "user.mycompany:myfile: re" in c.out assert "user.mycompany:myother: fnmatch" in c.out assert "user.mycompany:myfunct: re.search" in c.out