Skip to content

Commit

Permalink
fix conf evaluation types (#15779)
Browse files Browse the repository at this point in the history
* fix conf evaluation types

* fix test
  • Loading branch information
memsharded authored Feb 29, 2024
1 parent 0d09f6b commit 1dfe755
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 10 additions & 9 deletions conans/model/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import numbers
import re
import os
import fnmatch
Expand Down Expand Up @@ -650,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 isinstance(parsed_value, str): # xxx:xxx = "my string"
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 = {}
Expand Down
17 changes: 17 additions & 0 deletions conans/test/integration/configuration/conf/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,20 @@ 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 *")
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

0 comments on commit 1dfe755

Please sign in to comment.