Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit ae1f609

Browse files
authored
Test and impl for stripping whitespace off option tokens (#389)
Shell scripts that invoke the generator may construct the gapic generator options via formatted string concatenation and may contain escaped newlines. Proper parsing includes stripping whitespace after tokenizing from a comma-delimited string.
1 parent 1e76096 commit ae1f609

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

gapic/generator/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def build(cls, opt_string: str) -> 'Options':
7070
# Parse out every option beginning with `python-gapic`
7171
opts: DefaultDict[str, List[str]] = defaultdict(list)
7272
for opt in opt_string.split(','):
73+
opt = opt.strip()
7374
# Parse out the key and value.
7475
value = 'true'
7576
if '=' in opt:

tests/unit/generator/test_options.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ def test_options_unrecognized_likely_typo():
5252
assert len(warn.mock_calls) == 0
5353

5454

55+
def test_options_trim_whitespace():
56+
# When writing shell scripts, users may construct options strings with
57+
# whitespace that needs to be trimmed after tokenizing.
58+
opts = options.Options.build(
59+
'''
60+
python-gapic-templates=/squid/clam/whelk ,
61+
python-gapic-name=mollusca ,
62+
''')
63+
assert opts.templates[0] == '/squid/clam/whelk'
64+
assert opts.name == 'mollusca'
65+
66+
5567
def test_options_no_valid_sample_config(fs):
5668
fs.create_file("sampledir/not_a_config.yaml")
5769
with pytest.raises(types.InvalidConfig):

0 commit comments

Comments
 (0)