From a96751d01039181363b987200ac30e1df02c7f82 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Tue, 4 Jul 2017 21:37:28 +0300 Subject: [PATCH] Patch for the 'test_parse_cmd_args_with_quotes' test case Fixes #54 Related to commit 4a01626f9b83521603c1221f3bfcbfef08fa6549 --- youtube_dl_gui/parsers.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/youtube_dl_gui/parsers.py b/youtube_dl_gui/parsers.py index b06caba..dea0189 100644 --- a/youtube_dl_gui/parsers.py +++ b/youtube_dl_gui/parsers.py @@ -121,6 +121,7 @@ class OptionsParser(object): List of strings with all the youtube-dl command line options. """ + # REFACTOR options_list = ['--newline'] # Create a copy of options_dictionary @@ -181,8 +182,33 @@ class OptionsParser(object): options_list.append(to_string(value)) # Parse cmd_args - for option in options_dict['cmd_args'].split(): - options_list.append(option) + + # Indicates whether an item needs special handling + special_case = False + + # Temp list to hold special items + special_items = [] + + for item in options_dict["cmd_args"].split(): + + # Its a special case if its already a special case + # or an item starts with double quotes + special_case = (special_case or item[0] == "\"") + + if special_case: + special_items.append(item) + else: + options_list.append(item) + + # If its a special case and we meet a double quote + # at the end of the item, special case is over and + # we need to join, filter and append our special items + # to the options list + if special_case and item[-1] == "\"": + options_list.append(" ".join(special_items)[1:-1]) + + special_case = False + special_items = [] return options_list