# Buggy code
def _special_cases(self, cmd, outside):
    break_flag = False
    continue_flag = False
    args = parse_quotes(cmd)
    cmd_stripped = cmd.strip()

    if not cmd_stripped and cmd:
        # add scope if there are only spaces
        cmd = self.default_command + " " + cmd
    elif cmd_stripped == "quit" or cmd_stripped == "exit":
        break_flag = True
    elif cmd_stripped == "clear-history":
        continue_flag = True
        self.reset_history()
    elif cmd_stripped == CLEAR_WORD:
        outside = True
        cmd = CLEAR_WORD
    elif cmd_stripped[0] == SELECT_SYMBOL["outside"]:
        cmd = cmd_stripped[1:]
        outside = True
        if cmd.strip() and cmd.split()[0] == "cd":
            self.handle_cd(parse_quotes(cmd))
            continue_flag = True
        telemetry.track_outside_gesture()

    elif cmd_stripped[0] == SELECT_SYMBOL["exit_code"]:
        meaning = "Success" if self.last_exit == 0 else "Failure"

        print(meaning + ": " + str(self.last_exit), file=self.output)
        continue_flag = True
        telemetry.track_exit_code_gesture()
    elif SELECT_SYMBOL["query"] in cmd_stripped and self.last and self.last.result:
        continue_flag = self.handle_jmespath_query(args)
        telemetry.track_query_gesture()

    elif args[0] == "--version" or args[0] == "-v":
        try:
            continue_flag = True
            self.cli_ctx.show_version()
        except SystemExit:
            pass
    elif SELECT_SYMBOL["example"] in cmd:
        cmd, continue_flag = self.handle_example(cmd, continue_flag)
        telemetry.track_ran_tutorial()
    elif SELECT_SYMBOL["scope"] == cmd_stripped[0:2]:
        continue_flag, cmd = self.handle_scoping_input(continue_flag, cmd, cmd_stripped)
        telemetry.track_scope_changes()
    else:
        # not a special character; add scope and remove 'az'
        if self.default_command:
            cmd = self.default_command + " " + cmd
        elif cmd.split(" ", 1)[0].lower() == "az":
            cmd = " ".join(cmd.split()[1:])
        if "|" in cmd or ">" in cmd:
            # anything I don't parse, send off
            outside = True
            cmd = "az " + cmd
        telemetry.track_cli_commands_used()

    return break_flag, continue_flag, outside, cmd


# Traceback (ValueError)
az>> \
No escaped character
Traceback (most recent call last):
File "C:\Users\wilx\azure-cli\env36\lib\site-packages\knack\cli.py", line 194, in invoke
cmd_result = self.invocation.execute(args)
File "c:\users\wilx\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 347, in execute
six.reraise(*sys.exc_info())
File "C:\Users\wilx\azure-cli\env36\lib\site-packages\six.py", line 693, in reraise
raise value
File "c:\users\wilx\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 319, in execute
result = cmd(params)
File "c:\users\wilx\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 180, in __call__
return super(AzCliCommand, self).__call__(*args, **kwargs)
File "C:\Users\wilx\azure-cli\env36\lib\site-packages\knack\commands.py", line 109, in __call__
return self.handler(*args, **kwargs)
File "c:\users\wilx\azure-cli\src\azure-cli-core\azure\cli\core\__init__.py", line 418, in default_command_handler
result = op(**command_args)
File "c:\users\wilx\azure-cli\src\command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\__init__.py", line 13, in start_shell
AzInteractiveShell(cmd.cli_ctx, style)()
File "c:\users\wilx\azure-cli\src\command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\app.py", line 144, in __call__
self.run()
File "c:\users\wilx\azure-cli\src\command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\app.py", line 715, in run
b_flag, c_flag, outside, cmd = self._special_cases(cmd, outside)
File "c:\users\wilx\azure-cli\src\command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\app.py", line 470, in _special_cases
args = parse_quotes(cmd)
File "c:\users\wilx\azure-cli\src\command_modules\azure-cli-interactive\azure\cli\command_modules\interactive\azclishell\util.py", line 59, in parse_quotes
args = shlex.split(cmd)
File "C:\Users\wilx\AppData\Local\Programs\Python\Python36-32\lib\shlex.py", line 305, in split
return list(lex)
File "C:\Users\wilx\AppData\Local\Programs\Python\Python36-32\lib\shlex.py", line 295, in __next__
token = self.get_token()
File "C:\Users\wilx\AppData\Local\Programs\Python\Python36-32\lib\shlex.py", line 105, in get_token
raw = self.read_token()
File "C:\Users\wilx\AppData\Local\Programs\Python\Python36-32\lib\shlex.py", line 206, in read_token
raise ValueError("No escaped character")
ValueError: No escaped character

# Fixed code
def _special_cases(self, cmd, outside):
    break_flag = False
    continue_flag = False
    args = parse_quotes(cmd)
    cmd_stripped = cmd.strip()

    if not cmd_stripped and cmd:
        # add scope if there are only spaces
        cmd = self.default_command + " " + cmd
    elif cmd_stripped == "quit" or cmd_stripped == "exit":
        break_flag = True
    elif cmd_stripped == "clear-history":
        continue_flag = True
        self.reset_history()
    elif cmd_stripped == CLEAR_WORD:
        outside = True
        cmd = CLEAR_WORD
    elif cmd_stripped[0] == SELECT_SYMBOL["outside"]:
        cmd = cmd_stripped[1:]
        outside = True
        if cmd.strip() and cmd.split()[0] == "cd":
            self.handle_cd(parse_quotes(cmd))
            continue_flag = True
        telemetry.track_outside_gesture()

    elif cmd_stripped[0] == SELECT_SYMBOL["exit_code"]:
        meaning = "Success" if self.last_exit == 0 else "Failure"

        print(meaning + ": " + str(self.last_exit), file=self.output)
        continue_flag = True
        telemetry.track_exit_code_gesture()
    elif SELECT_SYMBOL["query"] in cmd_stripped and self.last and self.last.result:
        continue_flag = self.handle_jmespath_query(args)
        telemetry.track_query_gesture()
    elif not args:
        continue_flag = True
    elif args[0] == "--version" or args[0] == "-v":
        try:
            continue_flag = True
            self.cli_ctx.show_version()
        except SystemExit:
            pass
    elif SELECT_SYMBOL["example"] in cmd:
        cmd, continue_flag = self.handle_example(cmd, continue_flag)
        telemetry.track_ran_tutorial()
    elif SELECT_SYMBOL["scope"] == cmd_stripped[0:2]:
        continue_flag, cmd = self.handle_scoping_input(continue_flag, cmd, cmd_stripped)
        telemetry.track_scope_changes()
    else:
        # not a special character; add scope and remove 'az'
        if self.default_command:
            cmd = self.default_command + " " + cmd
        elif cmd.split(" ", 1)[0].lower() == "az":
            cmd = " ".join(cmd.split()[1:])
        if "|" in cmd or ">" in cmd:
            # anything I don't parse, send off
            outside = True
            cmd = "az " + cmd
        telemetry.track_cli_commands_used()

    return break_flag, continue_flag, outside, cmd