Skip to content

Commit 6765a09

Browse files
committed
Merge branch 'release/0.19.3'
2 parents 267791f + 90ea110 commit 6765a09

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

conans/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
COMPLEX_SEARCH_CAPABILITY = "complex_search"
1414
SERVER_CAPABILITIES = [COMPLEX_SEARCH_CAPABILITY, ]
1515

16-
__version__ = '0.19.2'
16+
__version__ = '0.19.3'

conans/model/info.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ def create(settings, options, requires, indirect_requires, non_devs_requirements
188188
@staticmethod
189189
def loads(text):
190190
parser = ConfigParser(text, ["settings", "full_settings", "options", "full_options",
191-
"requires", "full_requires", "scope", "recipe_hash"])
191+
"requires", "full_requires", "scope", "recipe_hash"],
192+
raise_unexpected_field=False)
192193

193194
result = ConanInfo()
194195
result.settings = Values.loads(parser.settings)

conans/test/server/conf_test.py

+31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from conans.errors import ConanException
2+
from conans.util.config_parser import ConfigParser
13
import unittest
24
from conans.util.files import save
35
import os
@@ -38,6 +40,35 @@ def setUp(self):
3840
save(server_conf, fileconfig % self.storage_path)
3941
self.environ = {}
4042

43+
def test_unexpected_section(self):
44+
text = """
45+
[one]
46+
text=value
47+
[two]
48+
other=var
49+
[three]
50+
var
51+
[moon]
52+
var=walker
53+
"""
54+
55+
self.assertRaises(ConanException, ConfigParser, text, ["one", "two", "three"])
56+
conf = ConfigParser(text, ["one", "two", "three"], raise_unexpected_field=False)
57+
self.assertEquals(conf.one, "text=value")
58+
self.assertEquals(conf.two, "other=var")
59+
self.assertEquals(conf.three, "var")
60+
self.assertEquals(conf.moon, "var=walker")
61+
with self.assertRaisesRegexp(ConanException, "Unrecognized field 'NOEXIST'"):
62+
conf.NOEXIST
63+
64+
# IF an old config file is readed but the section is in the list, just return it empty
65+
text = """
66+
[one]
67+
text=value
68+
"""
69+
conf = ConfigParser(text, ["one", "two", "three"], raise_unexpected_field=False)
70+
self.assertEquals(conf.two, "")
71+
4172
def test_values(self):
4273
config = ConanServerConfigParser(self.file_path, environment=self.environ)
4374
self.assertEquals(config.jwt_secret, "mysecret")

conans/util/config_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ConfigParser(object):
2626
as parser.section
2727
Currently used in ConanInfo and ConanFileTextLoader
2828
"""
29-
def __init__(self, text, allowed_fields=None, parse_lines=False):
29+
def __init__(self, text, allowed_fields=None, parse_lines=False, raise_unexpected_field=True):
3030
self._sections = {}
3131
self._allowed_fields = allowed_fields or []
3232
pattern = re.compile("^\[([a-z_]{2,50})\]")
@@ -43,7 +43,7 @@ def __init__(self, text, allowed_fields=None, parse_lines=False):
4343
else:
4444
raise ConanException("ConfigParser: Bad syntax '%s'" % line)
4545
if field:
46-
if self._allowed_fields and field not in self._allowed_fields:
46+
if self._allowed_fields and field not in self._allowed_fields and raise_unexpected_field:
4747
raise ConanException("ConfigParser: Unrecognized field '%s'" % field)
4848
current_lines = []
4949
self._sections[field] = current_lines

0 commit comments

Comments
 (0)