about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-08-27 00:16:57 +0100
committerJames Booth <boothj5@gmail.com>2013-08-27 00:16:57 +0100
commit133614d749b108fba8f1946d441d1aa958c2883b (patch)
tree218983c29a4f465014a41bf05a40a20b6ade3ac4
parent8045b949a7089be12fb7caaf2e4f355900c94e74 (diff)
parentbac97125a33aeacc9d1bc70c557ee53c2c3459d4 (diff)
downloadprofani-tty-133614d749b108fba8f1946d441d1aa958c2883b.tar.gz
Merge branch 'master' into windows
-rw-r--r--src/tools/parser.c2
-rw-r--r--tests/test_parser.c39
2 files changed, 40 insertions, 1 deletions
diff --git a/src/tools/parser.c b/src/tools/parser.c
index dabf7128..f273923a 100644
--- a/src/tools/parser.c
+++ b/src/tools/parser.c
@@ -210,7 +210,7 @@ parse_args_with_freetext(const char * const inp, int min, int max)
             } else {
                 in_token = TRUE;
                 num_tokens++;
-                if (num_tokens == max + 1) {
+                if ((num_tokens == max + 1) && (curr_uni != '"')) {
                     in_freetext = TRUE;
                 } else if (curr_uni == '"') {
                     in_quotes = TRUE;
diff --git a/tests/test_parser.c b/tests/test_parser.c
index 6df5eb1d..6295aafd 100644
--- a/tests/test_parser.c
+++ b/tests/test_parser.c
@@ -293,6 +293,42 @@ parse_cmd_with_quoted_freetext(void)
 }
 
 void
+parse_cmd_with_third_arg_quoted_0_min_3_max(void)
+{
+    char *inp = "/group add friends \"The User\"";
+    gchar **result = parse_args_with_freetext(inp, 0, 3);
+
+    assert_int_equals(3, g_strv_length(result));
+    assert_string_equals("add", result[0]);
+    assert_string_equals("friends", result[1]);
+    assert_string_equals("The User", result[2]);
+}
+
+void
+parse_cmd_with_second_arg_quoted_0_min_3_max(void)
+{
+    char *inp = "/group add \"The Group\" friend";
+    gchar **result = parse_args_with_freetext(inp, 0, 3);
+
+    assert_int_equals(3, g_strv_length(result));
+    assert_string_equals("add", result[0]);
+    assert_string_equals("The Group", result[1]);
+    assert_string_equals("friend", result[2]);
+}
+
+void
+parse_cmd_with_second_and_third_arg_quoted_0_min_3_max(void)
+{
+    char *inp = "/group add \"The Group\" \"The User\"";
+    gchar **result = parse_args_with_freetext(inp, 0, 3);
+
+    assert_int_equals(3, g_strv_length(result));
+    assert_string_equals("add", result[0]);
+    assert_string_equals("The Group", result[1]);
+    assert_string_equals("The User", result[2]);
+}
+
+void
 count_one_token(void)
 {
     char *inp = "one";
@@ -451,4 +487,7 @@ register_parser_tests(void)
     TEST(get_first_two_of_three_first_quoted);
     TEST(get_first_two_of_three_second_quoted);
     TEST(get_first_two_of_three_first_and_second_quoted);
+    TEST(parse_cmd_with_third_arg_quoted_0_min_3_max);
+    TEST(parse_cmd_with_second_arg_quoted_0_min_3_max);
+    TEST(parse_cmd_with_second_and_third_arg_quoted_0_min_3_max);
 }