Compare commits

..

1 Commits

Author SHA1 Message Date
Serghei Mihai 57c3babdc9 wscalls: unflatten payload when calling webservice (#66916)
gitea/wcs/pipeline/head This commit looks good Details
2024-03-24 22:21:02 +01:00
2 changed files with 5 additions and 3 deletions

View File

@ -591,12 +591,12 @@ def test_webservice_with_unflattened_payload_keys(http_requests, pub):
item = WebserviceCallStatusItem()
item.url = 'http://remote.example.net'
item.post_data = {'foo/0': 'first', 'foo/1': 'second', 'bar': 'example'}
item.post_data = {'foo/0': 'first', 'foo/1': 'second', 'bar': 'example', 'random//field': 'value'}
item.perform(formdata)
assert http_requests.get_last('url') == 'http://remote.example.net/'
assert http_requests.get_last('method') == 'POST'
payload = json.loads(http_requests.get_last('body'))
assert payload == {'foo': ['first', 'second'], 'bar': 'example'}
assert payload == {'foo': ['first', 'second'], 'bar': 'example', 'random/field': 'value'}
assert http_requests.count() == 1
http_requests.empty()

View File

@ -17,6 +17,7 @@
import collections
import hashlib
import json
import re
import urllib.parse
import xml.etree.ElementTree as ET
@ -72,10 +73,11 @@ def unflatten_keys(d):
if misc.is_ascii_digit(x):
return int(x)
elif isinstance(x, str):
# allow / char escaping
return x.replace('//', '/')
return x
return [map_key(x) for x in key.split('/')]
return [map_key(x) for x in re.split(r'(?<!/)/(?!/)', key)]
keys = [(split_key(key), key) for key in d]
try: