Skip to content
Open
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
7 changes: 7 additions & 0 deletions botocore/configloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ def raw_config_parse(config_filename, parse_subsections=True):
raise botocore.exceptions.ConfigParseError(
path=_unicode_path(path), error=e
) from None
elif parse_subsections and config_value == '':
# An empty value for a subsection key (e.g.
# "s3 =" with nothing after it) should be
# treated as an empty mapping rather than an
# empty string, so that downstream code
# expecting a dict does not break.
config_value = {}
config[section][option] = config_value
return config

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/cfg/aws_config_nested_empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[default]
aws_access_key_id = foo
aws_secret_access_key = bar
s3 =
region=us-west-2
18 changes: 18 additions & 0 deletions tests/unit/test_configloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ def test_nested_hierarchy_with_no_subsection_parsing(self):
'\nsignature_version = s3v4\naddressing_style = path',
)

def test_nested_hierarchy_with_empty_subsection(self):
filename = path('aws_config_nested_empty')
loaded_config = load_config(filename)
config = loaded_config['profiles']['default']
self.assertEqual(config['aws_access_key_id'], 'foo')
self.assertEqual(config['region'], 'us-west-2')
# An empty subsection value (e.g. "s3 =" with nothing after
# it) should be treated as an empty dict, not an empty string.
self.assertEqual(config['s3'], {})

def test_nested_hierarchy_empty_subsection_allows_get(self):
filename = path('aws_config_nested_empty')
loaded_config = load_config(filename)
config = loaded_config['profiles']['default']
# This should not raise AttributeError on the empty dict.
result = config.get('s3', {}).get('use_dualstack_endpoint')
self.assertIsNone(result)

def test_nested_bad_config(self):
filename = path('aws_config_nested_bad')
with self.assertRaises(botocore.exceptions.ConfigParseError):
Expand Down