diff options
| author | jvoisin | 2017-10-23 23:40:06 +0200 |
|---|---|---|
| committer | jvoisin | 2017-10-23 23:40:06 +0200 |
| commit | ca51803abbe0b5605f936f5676d9c1a528713033 (patch) | |
| tree | d93df6521a23882b8f3d44c06326574b3c66cb35 | |
| parent | 2c4251457f519e02bda073cbeb88c6d9778fa9ba (diff) | |
Add a test for unmatched brackets
| -rw-r--r-- | src/sp_config_utils.c | 5 | ||||
| -rw-r--r-- | src/tests/broken_unmatching_brackets.phpt | 9 | ||||
| -rw-r--r-- | src/tests/config/config_unmatching_brackets.ini | 1 |
3 files changed, 12 insertions, 3 deletions
diff --git a/src/sp_config_utils.c b/src/sp_config_utils.c index f562ffd..62fb7c1 100644 --- a/src/sp_config_utils.c +++ b/src/sp_config_utils.c | |||
| @@ -2,9 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | size_t sp_line_no; | 3 | size_t sp_line_no; |
| 4 | 4 | ||
| 5 | static int validate_str(const char *value); | 5 | static int validate_str(const char *value) { |
| 6 | |||
| 7 | static sp_pure int validate_str(const char *value) { | ||
| 8 | int balance = 0; // ghetto [] validation | 6 | int balance = 0; // ghetto [] validation |
| 9 | 7 | ||
| 10 | if (!strchr(value, '[')) { | 8 | if (!strchr(value, '[')) { |
| @@ -18,6 +16,7 @@ static sp_pure int validate_str(const char *value) { | |||
| 18 | balance--; | 16 | balance--; |
| 19 | } | 17 | } |
| 20 | if (balance < 0) { | 18 | if (balance < 0) { |
| 19 | sp_log_err("config", "The string '%s' contains unbalanced brackets.", value); | ||
| 21 | return -1; | 20 | return -1; |
| 22 | } | 21 | } |
| 23 | } | 22 | } |
diff --git a/src/tests/broken_unmatching_brackets.phpt b/src/tests/broken_unmatching_brackets.phpt new file mode 100644 index 0000000..14b9414 --- /dev/null +++ b/src/tests/broken_unmatching_brackets.phpt | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | --TEST-- | ||
| 2 | Broken configuration - unmatching brackets | ||
| 3 | --SKIPIF-- | ||
| 4 | <?php if (!extension_loaded("snuffleupagus")) die "skip"; ?> | ||
| 5 | --INI-- | ||
| 6 | sp.configuration_file={PWD}/config/config_unmatching_brackets.ini | ||
| 7 | --FILE-- | ||
| 8 | --EXPECTF-- | ||
| 9 | [snuffleupagus][0.0.0.0][config][error] The string 'arr[b]]]]]' contains unbalanced brackets. | ||
diff --git a/src/tests/config/config_unmatching_brackets.ini b/src/tests/config/config_unmatching_brackets.ini new file mode 100644 index 0000000..45fa4fe --- /dev/null +++ b/src/tests/config/config_unmatching_brackets.ini | |||
| @@ -0,0 +1 @@ | |||
| sp.disable_function.function("foo").param("arr[b]]]]]").value("aaa").alias("4").drop(); | |||
