mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-25 00:37:31 +02:00
fix query for non-http schemes. Set null for empty fields
This commit is contained in:
@ -21,8 +21,17 @@ Schema:
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ echo "http://example.com/test/path?q1=foo&q2=bar#frag" | jc --url -p
|
% echo "http://example.com/test/path?q1=foo&q2=bar#frag" | jc --url -p
|
||||||
[]
|
{
|
||||||
|
"scheme": "http",
|
||||||
|
"netloc": "example.com",
|
||||||
|
"path": "/test/path",
|
||||||
|
"query": {
|
||||||
|
"q1": "foo",
|
||||||
|
"q2": "bar"
|
||||||
|
},
|
||||||
|
"fragment": "frag"
|
||||||
|
}
|
||||||
|
|
||||||
$ FTP example, etc.
|
$ FTP example, etc.
|
||||||
[]
|
[]
|
||||||
@ -84,19 +93,23 @@ def parse(
|
|||||||
|
|
||||||
if jc.utils.has_data(data):
|
if jc.utils.has_data(data):
|
||||||
parts = urlparse(data)
|
parts = urlparse(data)
|
||||||
query_list = parts.query.split('&')
|
query = {}
|
||||||
query: Dict = {}
|
query_list = []
|
||||||
|
|
||||||
for q in query_list:
|
if parts.query:
|
||||||
k, v = q.split('=')
|
query_list = parts.query.split('&')
|
||||||
query.update({k: v})
|
|
||||||
|
if query_list:
|
||||||
|
for q in query_list:
|
||||||
|
k, v = q.split('=')
|
||||||
|
query.update({k: v})
|
||||||
|
|
||||||
raw_output = {
|
raw_output = {
|
||||||
'scheme': parts.scheme,
|
'scheme': parts.scheme or None,
|
||||||
'netloc': parts.netloc,
|
'netloc': parts.netloc or None,
|
||||||
'path': parts.path,
|
'path': parts.path or None,
|
||||||
'query': query,
|
'query': query or None,
|
||||||
'fragment': parts.fragment
|
'fragment': parts.fragment or None
|
||||||
}
|
}
|
||||||
|
|
||||||
return raw_output if raw else _process(raw_output)
|
return raw_output if raw else _process(raw_output)
|
||||||
|
Reference in New Issue
Block a user