File tree 3 files changed +36
-3
lines changed
3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
8
8
## [ Unreleased]
9
9
10
+ ### Fixed
11
+
12
+ - Fix parse fail when header has multiple '=' characters [ #440 ] ( https://github.com/stac-utils/pystac-client/pull/440 )
13
+
10
14
## [ v0.6.0] - 2023-01-27
11
15
12
16
### Added
Original file line number Diff line number Diff line change 2
2
import json
3
3
import logging
4
4
import os
5
+ import re
5
6
import sys
6
7
from typing import Any , Dict , List , Optional
7
8
@@ -191,10 +192,11 @@ def parse_args(args: List[str]) -> Dict[str, Any]:
191
192
# if headers provided, parse it
192
193
if "headers" in parsed_args :
193
194
new_headers = {}
195
+ splitter = re .compile ("^([^=]+)=(.+)$" )
194
196
for head in parsed_args ["headers" ]:
195
- parts = head . split ( "=" )
196
- if len ( parts ) == 2 :
197
- new_headers [parts [ 0 ]] = parts [ 1 ]
197
+ match = splitter . match ( head )
198
+ if match :
199
+ new_headers [match . group ( 1 )] = match . group ( 2 )
198
200
else :
199
201
logger .warning (f"Unable to parse header { head } " )
200
202
parsed_args ["headers" ] = new_headers
Original file line number Diff line number Diff line change
1
+ from typing import List
2
+
1
3
import pytest
2
4
from pytest_console_scripts import ScriptRunner
3
5
6
+ import pystac_client .cli
4
7
from tests .helpers import STAC_URLS
5
8
6
9
@@ -19,6 +22,30 @@ def test_item_search(self, script_runner: ScriptRunner) -> None:
19
22
result = script_runner .run (* args , print_result = False )
20
23
assert result .success
21
24
25
+ @pytest .mark .parametrize (
26
+ "headers,good_header_count" ,
27
+ [
28
+ (["kick=flip" , "home=run" ], 2 ),
29
+ (["mad=pow" ], 1 ),
30
+ (["=no-var" ], 0 ),
31
+ (["no-val=" ], 0 ),
32
+ (["good=header" , "bad-header" ], 1 ),
33
+ (["header=value-with-three-=-signs-=" , "plain=jane" ], 2 ),
34
+ ],
35
+ )
36
+ def test_headers (self , headers : List [str ], good_header_count : int ) -> None :
37
+ args = [
38
+ "search" ,
39
+ STAC_URLS ["PLANETARY-COMPUTER" ],
40
+ "-c" ,
41
+ "naip" ,
42
+ "--max-items" ,
43
+ "20" ,
44
+ "--headers" ,
45
+ ] + headers
46
+ pargs = pystac_client .cli .parse_args (args )
47
+ assert len (pargs ["headers" ]) == good_header_count
48
+
22
49
def test_no_arguments (self , script_runner : ScriptRunner ) -> None :
23
50
args = ["stac-client" ]
24
51
result = script_runner .run (* args , print_result = False )
You can’t perform that action at this time.
0 commit comments