Skip to content

Commit 3137cdd

Browse files
committed
Add a query validity check
The QueryParser will check if all query's extensions are in the form extension_name(param,...)
1 parent 7cb43bc commit 3137cdd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/JSONDB/QueryParser.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function parse($query)
104104

105105
$this->notParsedQuery = $query;
106106

107-
// Getting query parts
107+
// Getting query's parts
108108
$queryParts = explode('.', $this->notParsedQuery);
109109

110110
// Getting the table name
@@ -113,6 +113,13 @@ public function parse($query)
113113
throw new Exception('JSONDB Query Parse Error: No table detected in the query.');
114114
}
115115

116+
// Checking query's parts validity
117+
foreach (array_slice($queryParts, 1) as $part) {
118+
if (FALSE === (bool)preg_match('#\w+\(.*\)#', $part)) {
119+
throw new Exception("JSONDB Query Parse Error: There is an error at the extension \"{$part}\".");
120+
}
121+
}
122+
116123
// Getting the query's main action
117124
$this->parsedQuery['action'] = preg_replace('#\(.*\)#', '', $queryParts[1]);
118125
if (!in_array(strtolower($this->parsedQuery['action']), self::$supportedQueries, TRUE)) {

0 commit comments

Comments
 (0)