Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Add a test for unmatched brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin committed Oct 23, 2017
1 parent 2c42514 commit ca51803
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/sp_config_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

size_t sp_line_no;

static int validate_str(const char *value);

static sp_pure int validate_str(const char *value) {
static int validate_str(const char *value) {
int balance = 0; // ghetto [] validation

if (!strchr(value, '[')) {
Expand All @@ -18,6 +16,7 @@ static sp_pure int validate_str(const char *value) {
balance--;
}
if (balance < 0) {
sp_log_err("config", "The string '%s' contains unbalanced brackets.", value);
return -1;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/tests/broken_unmatching_brackets.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--TEST--
Broken configuration - unmatching brackets
--SKIPIF--
<?php if (!extension_loaded("snuffleupagus")) die "skip"; ?>
--INI--
sp.configuration_file={PWD}/config/config_unmatching_brackets.ini
--FILE--
--EXPECTF--
[snuffleupagus][0.0.0.0][config][error] The string 'arr[b]]]]]' contains unbalanced brackets.
1 change: 1 addition & 0 deletions src/tests/config/config_unmatching_brackets.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sp.disable_function.function("foo").param("arr[b]]]]]").value("aaa").alias("4").drop();

0 comments on commit ca51803

Please sign in to comment.