Skip to content

Commit 9a42673

Browse files
ircwavesgadomski
authored andcommitted
fix(cli): header parsing when multiple equals present
1 parent 4093002 commit 9a42673

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fix parse fail when header has multiple '=' characters [#440](https://github.com/stac-utils/pystac-client/pull/440)
13+
1014
## [v0.6.0] - 2023-01-27
1115

1216
### Added

pystac_client/cli.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import os
5+
import re
56
import sys
67
from typing import Any, Dict, List, Optional
78

@@ -191,10 +192,11 @@ def parse_args(args: List[str]) -> Dict[str, Any]:
191192
# if headers provided, parse it
192193
if "headers" in parsed_args:
193194
new_headers = {}
195+
splitter = re.compile("^([^=]+)=(.+)$")
194196
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)
198200
else:
199201
logger.warning(f"Unable to parse header {head}")
200202
parsed_args["headers"] = new_headers

tests/test_cli.py

+27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from typing import List
2+
13
import pytest
24
from pytest_console_scripts import ScriptRunner
35

6+
import pystac_client.cli
47
from tests.helpers import STAC_URLS
58

69

@@ -19,6 +22,30 @@ def test_item_search(self, script_runner: ScriptRunner) -> None:
1922
result = script_runner.run(*args, print_result=False)
2023
assert result.success
2124

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+
2249
def test_no_arguments(self, script_runner: ScriptRunner) -> None:
2350
args = ["stac-client"]
2451
result = script_runner.run(*args, print_result=False)

0 commit comments

Comments
 (0)