diff --git a/cli/openbb_cli/controllers/utils.py b/cli/openbb_cli/controllers/utils.py index 1203afc19ddc..487e448b77b8 100644 --- a/cli/openbb_cli/controllers/utils.py +++ b/cli/openbb_cli/controllers/utils.py @@ -340,8 +340,10 @@ def parse_and_split_input(an_input: str, custom_filters: list) -> list[str]: return list(filter(None, commands)) matching_placeholders = [tag for tag in placeholders if tag in command] if len(matching_placeholders) > 0: + restored = command for tag in matching_placeholders: - commands[command_num] = command.replace(tag, placeholders[tag]) + restored = restored.replace(tag, placeholders[tag]) + commands[command_num] = restored return list(filter(None, commands)) diff --git a/cli/tests/test_queue_multiple_file_arguments.py b/cli/tests/test_queue_multiple_file_arguments.py new file mode 100644 index 000000000000..03eac20dd275 --- /dev/null +++ b/cli/tests/test_queue_multiple_file_arguments.py @@ -0,0 +1,16 @@ +"""Queued commands must not leak internal placeholder tokens.""" + +from openbb_cli.controllers.utils import parse_and_split_input + + +def test_multiple_paths_in_one_queued_command(): + command = "load -f /tmp/first.csv --file /tmp/second.csv" + assert parse_and_split_input(command + "/echo done", []) == [command, "echo done"] + + +def test_custom_protected_arguments_are_all_restored(): + command = "echo [first/path] [second/path]" + assert parse_and_split_input(command + "/echo done", [r"\[[^\]]+\]"]) == [ + command, + "echo done", + ]