Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix conf evaluation types #15779

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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