Skip to content

Commit 9144bc4

Browse files
authored
Support # in user_agent_appid (#9967)
1 parent f1d9604 commit 9144bc4

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

awscli/botocore/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Config:
4141
:type user_agent_appid: str
4242
:param user_agent_appid: A value that gets included in the User-Agent
4343
string in the format "app/<user_agent_appid>". Allowed characters are
44-
ASCII alphanumerics and ``!$%&'*+-.^_`|~``. All other characters will
44+
ASCII alphanumerics and ``!#$%&'*+-.^_`|~``. All other characters will
4545
be replaced by a ``-``.
4646
4747
:type connect_timeout: float or int

awscli/botocore/useragent.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,10 @@ def _build_app_id(self):
585585
User-Agent header.
586586
"""
587587
if self._client_config and self._client_config.user_agent_appid:
588-
return [
589-
UserAgentComponent('app', self._client_config.user_agent_appid)
590-
]
588+
appid = sanitize_user_agent_string_component(
589+
raw_str=self._client_config.user_agent_appid, allow_hash=True
590+
)
591+
return [RawStringUserAgentComponent(f'app/{appid}')]
591592
else:
592593
return []
593594

tests/unit/botocore/test_useragent.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,27 @@ def test_non_positive_user_agent_component_size_config_raises():
236236
with pytest.raises(ValueError) as excinfo:
237237
UserAgentComponentSizeConfig(-1, ',')
238238
assert 'Invalid `max_size_in_bytes`' in str(excinfo.value)
239+
240+
241+
def test_hash_in_user_agent_appid():
242+
ua = UserAgentString(
243+
platform_name='linux',
244+
platform_version='1.2.3-foo',
245+
platform_machine='x86_64',
246+
python_version='3.8.20',
247+
python_implementation='Dpython',
248+
execution_env='AWS_Lambda_python3.8',
249+
).with_client_config(Config(user_agent_appid='fooapp#1.0.0'))
250+
251+
actual = ua.to_string()
252+
expected = (
253+
f'Botocore/{botocore_version} '
254+
'ua/2.1 '
255+
'os/linux#1.2.3-foo '
256+
'md/arch#x86_64 '
257+
'lang/python#3.8.20 '
258+
'md/pyimpl#Dpython '
259+
'exec-env/AWS_Lambda_python3.8 '
260+
'app/fooapp#1.0.0'
261+
)
262+
assert actual == expected

0 commit comments

Comments
 (0)