Skip to content

Commit

Permalink
bugfix: split_command_args trate the \n to 2 chars in quotes.
Browse files Browse the repository at this point in the history
fix: #489
  • Loading branch information
laixintao committed Feb 16, 2024
1 parent 3f39b7e commit 2df515f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion iredis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def split_command_args(command):
# `command` with `args` is ('in') which is an invalid case.
normalized_input_command = " ".join(command.split()).upper()
if (
re.search("\s", command)
re.search(r"\s", command)
and command_name.startswith(normalized_input_command)
and command_name != normalized_input_command
):
Expand Down
13 changes: 7 additions & 6 deletions iredis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ def literal_bytes(b):
return b


def _valid_token(words):
token = "".join(words).strip()
if token:
yield token
def nappend(word, c, pre_back_slash):
if pre_back_slash and c == "n": # \n
word[-1] = "\n"
else:
word.append(c)


def strip_quote_args(s):
Expand All @@ -69,7 +70,7 @@ def strip_quote_args(s):
# previous char is \ , merge with current "
word[-1] = char
else:
word.append(char)
nappend(word, char, pre_back_slash)
# not in quote
else:
# separator
Expand All @@ -81,7 +82,7 @@ def strip_quote_args(s):
elif char in ["'", '"']:
in_quote = char
else:
word.append(char)
nappend(word, char, pre_back_slash)
if char == "\\" and not pre_back_slash:
pre_back_slash = True
else:
Expand Down
1 change: 1 addition & 0 deletions tests/unittests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_timer():
(r'""', [""]), # set foo "" is a legal command
(r"\\", ["\\\\"]), # backslash are legal
("\\hello\\", ["\\hello\\"]), # backslash are legal
('foo "bar\\n1"', ["foo", "bar\n1"]),
],
)
def test_stripe_quote_escape_in_quote(test_input, expected):
Expand Down

0 comments on commit 2df515f

Please sign in to comment.