diff --git a/conans/client/profile_loader.py b/conans/client/profile_loader.py index cc4763fba8e..c532e6b6912 100644 --- a/conans/client/profile_loader.py +++ b/conans/client/profile_loader.py @@ -263,7 +263,6 @@ def get_profile(profile_text, base_profile=None): "options", "conf", "buildenv", "runenv", "replace_requires", "replace_tool_requires", "runner"]) - # Parse doc sections into Conan model, Settings, Options, etc settings, package_settings = _ProfileValueParser._parse_settings(doc) options = Options.loads(doc.options) if doc.options else None diff --git a/conans/util/config_parser.py b/conans/util/config_parser.py index 75d4ad93a74..8a7ac602fb0 100644 --- a/conans/util/config_parser.py +++ b/conans/util/config_parser.py @@ -44,6 +44,9 @@ def __init__(self, text, allowed_fields=None, strip_comments=False): if self._allowed_fields and field not in self._allowed_fields: raise ConanException("ConfigParser: Unrecognized field '%s'" % field) current_lines = [] + # Duplicated section + if field in self._sections: + raise ConanException(f"ConfigParser: Duplicated section: [{field}]") self._sections[field] = current_lines else: if current_lines is None: diff --git a/test/integration/configuration/profile_test.py b/test/integration/configuration/profile_test.py index d47dba871a3..1a93ea449cd 100644 --- a/test/integration/configuration/profile_test.py +++ b/test/integration/configuration/profile_test.py @@ -574,3 +574,42 @@ def configure(self): client.save({"conanfile.py": conanfile, "my_profile.txt": profile}) client.run("install . --profile my_profile.txt") assert "I'm hello and my build type is Debug" in client.out + + +def test_consumer_invalid_profile_multiple_groups(): + """ + Issue related: https://github.com/conan-io/conan/issues/16448 + """ + client = TestClient() + conanfile = GenConanfile(name="hello", version="1.0").with_settings("os", "arch", + "build_type", "compiler") + prof1 = textwrap.dedent("""\ + [settings] + arch=x86_64 + os=Linux + build_type=Release + compiler=clang + compiler.libcxx=libstdc++11 + compiler.version=18 + compiler.cppstd=20 + + [conf] + tools.build:compiler_executables={'c': '/usr/bin/clang-18', 'cpp': '/usr/bin/clang++-18'} + + [settings] + # Empty and duplicated section + + [options] + package/*:option=Whatever + + [conf] + # Another one + """) + client.save({ + "conanfile.py": conanfile, + "myprofs/myprofile": prof1 + }) + client.run("build . --profile:host myprofs/myprofile -g CMakeToolchain", + assert_error=True) + assert ("ERROR: Error reading 'myprofs/myprofile' profile: ConfigParser: " + "Duplicated section: [settings]") in client.out