Skip to content

Commit 7a6aa64

Browse files
authored
Merge pull request #22578 from guerler/fixes.005
[26.0] Fixes looks_like_flattened_repeat_key helper
2 parents c513048 + 0b1a57e commit 7a6aa64

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/galaxy/tools/parameters/wrapped.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ def process_key(incoming_key: str, incoming_value: Any, d: dict[str, Any]):
201201
else:
202202
# Section / Conditional
203203
input_name = key_parts[0]
204+
if not input_name or input_name.isdigit():
205+
raise RequestParameterInvalidException(f"Parameter '{incoming_key}' has an invalid key structure.")
204206
subdict = d.get(input_name, {})
205207
if not isinstance(subdict, dict):
206208
raise RequestParameterInvalidException(f"Parameter '{incoming_key}' received conflicting value.")

lib/galaxy/util/permutations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def is_in_state(state_dict, key, nested):
159159

160160

161161
def looks_like_flattened_repeat_key(key: str) -> bool:
162-
return key.rsplit("_", 1)[-1].isdigit()
162+
parts = key.rsplit("_", 1)
163+
return len(parts) == 2 and parts[1].isdigit()
163164

164165

165166
def split_flattened_repeat_key(key: str) -> Tuple[str, int]:

test/unit/app/tools/test_parameter_parsing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Any,
33
)
44

5+
import pytest
6+
7+
from galaxy.exceptions import RequestParameterInvalidException
58
from galaxy.tools.parameters.wrapped import (
69
nested_key_to_path,
710
process_key,
@@ -58,6 +61,11 @@ def test_process_key_2(self):
5861
}
5962
assert nested_dict == expected_dict
6063

64+
def test_process_key_rejects_all_digit_segment(self):
65+
nested_dict: dict[str, Any] = {}
66+
with pytest.raises(RequestParameterInvalidException):
67+
process_key("files|0|filetype", "fastq", nested_dict)
68+
6169

6270
class TestParameterParsing(BaseParameterTestCase):
6371
"""Test the parsing of XML for most parameter types - in many

0 commit comments

Comments
 (0)