Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Fix parse fail when header has multiple '=' characters [#440](https://github.com/stac-utils/pystac-client/pull/440)

## [v0.6.0] - 2023-01-27

### Added
Expand Down
8 changes: 5 additions & 3 deletions pystac_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import os
import re
import sys
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -191,10 +192,11 @@ def parse_args(args: List[str]) -> Dict[str, Any]:
# if headers provided, parse it
if "headers" in parsed_args:
new_headers = {}
splitter = re.compile("^([^=]+)=(.+)$")
for head in parsed_args["headers"]:
parts = head.split("=")
if len(parts) == 2:
new_headers[parts[0]] = parts[1]
match = splitter.match(head)
if match:
new_headers[match.group(1)] = match.group(2)
else:
logger.warning(f"Unable to parse header {head}")
parsed_args["headers"] = new_headers
Expand Down
27 changes: 27 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import List

import pytest
from pytest_console_scripts import ScriptRunner

import pystac_client.cli
from tests.helpers import STAC_URLS


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

@pytest.mark.parametrize(
"headers,good_header_count",
[
(["kick=flip", "home=run"], 2),
(["mad=pow"], 1),
(["=no-var"], 0),
(["no-val="], 0),
(["good=header", "bad-header"], 1),
(["header=value-with-three-=-signs-=", "plain=jane"], 2),
],
)
def test_headers(self, headers: List[str], good_header_count: int) -> None:
args = [
"search",
STAC_URLS["PLANETARY-COMPUTER"],
"-c",
"naip",
"--max-items",
"20",
"--headers",
] + headers
pargs = pystac_client.cli.parse_args(args)
assert len(pargs["headers"]) == good_header_count

def test_no_arguments(self, script_runner: ScriptRunner) -> None:
args = ["stac-client"]
result = script_runner.run(*args, print_result=False)
Expand Down