Skip to content

Commit

Permalink
fix: accepts fieldnames of size 2
Browse files Browse the repository at this point in the history
  • Loading branch information
valmoz committed Dec 2, 2021
1 parent 5c954bf commit b91898a
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 118 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ phpcs.xml
phpunit.xml
.phpunit.result.cache
.idea
.vscode
.DS_Store

8 changes: 4 additions & 4 deletions grammar/ApiFilter.g4
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ expression:

condition: FIELD op value;
op: EQ | GT | GTE | LT | LTE | NEQ | LIKE;
value: (BOOL | STRING | integer | double);
value: (BOOL | STRING | integer | decimal);

integer: INT;
double: INT DOT INT;
decimal: INT DOT INT;

/*
* Lexer Rules
Expand Down Expand Up @@ -46,10 +46,10 @@ DOT: '.';

INT: (DIGIT)+;

FIELD: LOWERCASE (( LOWERCASE | '_' | '.')+ LOWERCASE)?;
FIELD: LOWERCASE (( LOWERCASE | '_' | '.')* LOWERCASE)?;

fragment LOWERCASE: [a-z];
fragment UPPERCASE: [A-Z];
fragment DIGIT: [0-9];

WS: [ \t\r\n]+ -> skip;
WS: [ \t\r\n]+ -> skip;
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</report>
</coverage>
<testsuites>
<testsuite name=":vendor Test Suite">
<testsuite name="fattureincloud Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand Down
8 changes: 4 additions & 4 deletions src/ApiFilter/FilterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use FattureInCloud\ApiFilter\Parser\Context\FilterContext;
use FattureInCloud\ApiFilter\Parser\Context\ConditionExpContext;
use FattureInCloud\ApiFilter\Parser\Context\IntegerContext;
use FattureInCloud\ApiFilter\Parser\Context\DoubleContext;
use FattureInCloud\ApiFilter\Parser\Context\DecimalContext;
use FattureInCloud\ApiFilter\Parser\Context\ParenthesisExpContext;
use FattureInCloud\ApiFilter\Parser\Context\NegationExpContext;
use FattureInCloud\ApiFilter\Parser\Context\ConjunctionExpContext;
Expand Down Expand Up @@ -94,8 +94,8 @@ public function visitValue(ValueContext $context)
$value = filter_var($context->BOOL()->getText(), FILTER_VALIDATE_BOOLEAN);
} elseif ($context->integer()) {
$value = $this->visit($context->integer());
} elseif ($context->double()) {
$value = $this->visit($context->double());
} elseif ($context->decimal()) {
$value = $this->visit($context->decimal());
}
return $value;
}
Expand All @@ -105,7 +105,7 @@ public function visitInteger(IntegerContext $context)
return intval($context->getText());
}

public function visitDouble(DoubleContext $context)
public function visitDecimal(DecimalContext $context)
{
return floatval($context->getText());
}
Expand Down
2 changes: 1 addition & 1 deletion src/ApiFilter/Parser/ApiFilter.interp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ condition
op
value
integer
double
decimal


atn:
Expand Down
2 changes: 1 addition & 1 deletion src/ApiFilter/Parser/ApiFilterBaseVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function visitInteger(Context\IntegerContext $context)
* The default implementation returns the result of calling
* {@see self::visitChildren()} on `context`.
*/
public function visitDouble(Context\DoubleContext $context)
public function visitDecimal(Context\DecimalContext $context)
{
return $this->visitChildren($context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ApiFilter/Parser/ApiFilterLexer.interp
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ mode names:
DEFAULT_MODE

atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 20, 150, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 5, 7, 62, 10, 7, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 5, 8, 72, 10, 8, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 5, 9, 83, 10, 9, 3, 10, 3, 10, 3, 10, 3, 10, 6, 10, 89, 10, 10, 13, 10, 14, 10, 90, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 5, 11, 101, 10, 11, 3, 12, 3, 12, 3, 12, 3, 12, 5, 12, 107, 10, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 5, 13, 115, 10, 13, 3, 14, 3, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 17, 6, 17, 124, 10, 17, 13, 17, 14, 17, 125, 3, 18, 3, 18, 3, 18, 6, 18, 131, 10, 18, 13, 18, 14, 18, 132, 3, 18, 5, 18, 136, 10, 18, 3, 19, 3, 19, 3, 20, 3, 20, 3, 21, 3, 21, 3, 22, 6, 22, 145, 10, 22, 13, 22, 14, 22, 146, 3, 22, 3, 22, 2, 2, 23, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 35, 19, 37, 2, 39, 2, 41, 2, 43, 20, 3, 2, 8, 3, 2, 41, 41, 4, 2, 48, 48, 97, 97, 3, 2, 99, 124, 3, 2, 67, 92, 3, 2, 50, 59, 5, 2, 11, 12, 15, 15, 34, 34, 2, 159, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 3, 45, 3, 2, 2, 2, 5, 47, 3, 2, 2, 2, 7, 49, 3, 2, 2, 2, 9, 52, 3, 2, 2, 2, 11, 54, 3, 2, 2, 2, 13, 61, 3, 2, 2, 2, 15, 71, 3, 2, 2, 2, 17, 82, 3, 2, 2, 2, 19, 84, 3, 2, 2, 2, 21, 100, 3, 2, 2, 2, 23, 106, 3, 2, 2, 2, 25, 114, 3, 2, 2, 2, 27, 116, 3, 2, 2, 2, 29, 118, 3, 2, 2, 2, 31, 120, 3, 2, 2, 2, 33, 123, 3, 2, 2, 2, 35, 127, 3, 2, 2, 2, 37, 137, 3, 2, 2, 2, 39, 139, 3, 2, 2, 2, 41, 141, 3, 2, 2, 2, 43, 144, 3, 2, 2, 2, 45, 46, 7, 63, 2, 2, 46, 4, 3, 2, 2, 2, 47, 48, 7, 64, 2, 2, 48, 6, 3, 2, 2, 2, 49, 50, 7, 64, 2, 2, 50, 51, 7, 63, 2, 2, 51, 8, 3, 2, 2, 2, 52, 53, 7, 62, 2, 2, 53, 10, 3, 2, 2, 2, 54, 55, 7, 62, 2, 2, 55, 56, 7, 63, 2, 2, 56, 12, 3, 2, 2, 2, 57, 58, 7, 62, 2, 2, 58, 62, 7, 64, 2, 2, 59, 60, 7, 35, 2, 2, 60, 62, 7, 63, 2, 2, 61, 57, 3, 2, 2, 2, 61, 59, 3, 2, 2, 2, 62, 14, 3, 2, 2, 2, 63, 64, 7, 110, 2, 2, 64, 65, 7, 107, 2, 2, 65, 66, 7, 109, 2, 2, 66, 72, 7, 103, 2, 2, 67, 68, 7, 78, 2, 2, 68, 69, 7, 75, 2, 2, 69, 70, 7, 77, 2, 2, 70, 72, 7, 71, 2, 2, 71, 63, 3, 2, 2, 2, 71, 67, 3, 2, 2, 2, 72, 16, 3, 2, 2, 2, 73, 74, 7, 118, 2, 2, 74, 75, 7, 116, 2, 2, 75, 76, 7, 119, 2, 2, 76, 83, 7, 103, 2, 2, 77, 78, 7, 104, 2, 2, 78, 79, 7, 99, 2, 2, 79, 80, 7, 110, 2, 2, 80, 81, 7, 117, 2, 2, 81, 83, 7, 103, 2, 2, 82, 73, 3, 2, 2, 2, 82, 77, 3, 2, 2, 2, 83, 18, 3, 2, 2, 2, 84, 88, 7, 41, 2, 2, 85, 89, 10, 2, 2, 2, 86, 87, 7, 41, 2, 2, 87, 89, 7, 41, 2, 2, 88, 85, 3, 2, 2, 2, 88, 86, 3, 2, 2, 2, 89, 90, 3, 2, 2, 2, 90, 88, 3, 2, 2, 2, 90, 91, 3, 2, 2, 2, 91, 92, 3, 2, 2, 2, 92, 93, 7, 41, 2, 2, 93, 20, 3, 2, 2, 2, 94, 95, 7, 99, 2, 2, 95, 96, 7, 112, 2, 2, 96, 101, 7, 102, 2, 2, 97, 98, 7, 67, 2, 2, 98, 99, 7, 80, 2, 2, 99, 101, 7, 70, 2, 2, 100, 94, 3, 2, 2, 2, 100, 97, 3, 2, 2, 2, 101, 22, 3, 2, 2, 2, 102, 103, 7, 113, 2, 2, 103, 107, 7, 116, 2, 2, 104, 105, 7, 81, 2, 2, 105, 107, 7, 84, 2, 2, 106, 102, 3, 2, 2, 2, 106, 104, 3, 2, 2, 2, 107, 24, 3, 2, 2, 2, 108, 109, 7, 112, 2, 2, 109, 110, 7, 113, 2, 2, 110, 115, 7, 118, 2, 2, 111, 112, 7, 80, 2, 2, 112, 113, 7, 81, 2, 2, 113, 115, 7, 86, 2, 2, 114, 108, 3, 2, 2, 2, 114, 111, 3, 2, 2, 2, 115, 26, 3, 2, 2, 2, 116, 117, 7, 42, 2, 2, 117, 28, 3, 2, 2, 2, 118, 119, 7, 43, 2, 2, 119, 30, 3, 2, 2, 2, 120, 121, 7, 48, 2, 2, 121, 32, 3, 2, 2, 2, 122, 124, 5, 41, 21, 2, 123, 122, 3, 2, 2, 2, 124, 125, 3, 2, 2, 2, 125, 123, 3, 2, 2, 2, 125, 126, 3, 2, 2, 2, 126, 34, 3, 2, 2, 2, 127, 135, 5, 37, 19, 2, 128, 131, 5, 37, 19, 2, 129, 131, 9, 3, 2, 2, 130, 128, 3, 2, 2, 2, 130, 129, 3, 2, 2, 2, 131, 132, 3, 2, 2, 2, 132, 130, 3, 2, 2, 2, 132, 133, 3, 2, 2, 2, 133, 134, 3, 2, 2, 2, 134, 136, 5, 37, 19, 2, 135, 130, 3, 2, 2, 2, 135, 136, 3, 2, 2, 2, 136, 36, 3, 2, 2, 2, 137, 138, 9, 4, 2, 2, 138, 38, 3, 2, 2, 2, 139, 140, 9, 5, 2, 2, 140, 40, 3, 2, 2, 2, 141, 142, 9, 6, 2, 2, 142, 42, 3, 2, 2, 2, 143, 145, 9, 7, 2, 2, 144, 143, 3, 2, 2, 2, 145, 146, 3, 2, 2, 2, 146, 144, 3, 2, 2, 2, 146, 147, 3, 2, 2, 2, 147, 148, 3, 2, 2, 2, 148, 149, 8, 22, 2, 2, 149, 44, 3, 2, 2, 2, 16, 2, 61, 71, 82, 88, 90, 100, 106, 114, 125, 130, 132, 135, 146, 3, 8, 2, 2]
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 20, 151, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 7, 5, 7, 62, 10, 7, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 3, 8, 5, 8, 72, 10, 8, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 3, 9, 5, 9, 83, 10, 9, 3, 10, 3, 10, 3, 10, 3, 10, 6, 10, 89, 10, 10, 13, 10, 14, 10, 90, 3, 10, 3, 10, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 3, 11, 5, 11, 101, 10, 11, 3, 12, 3, 12, 3, 12, 3, 12, 5, 12, 107, 10, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 5, 13, 115, 10, 13, 3, 14, 3, 14, 3, 15, 3, 15, 3, 16, 3, 16, 3, 17, 6, 17, 124, 10, 17, 13, 17, 14, 17, 125, 3, 18, 3, 18, 3, 18, 7, 18, 131, 10, 18, 12, 18, 14, 18, 134, 11, 18, 3, 18, 5, 18, 137, 10, 18, 3, 19, 3, 19, 3, 20, 3, 20, 3, 21, 3, 21, 3, 22, 6, 22, 146, 10, 22, 13, 22, 14, 22, 147, 3, 22, 3, 22, 2, 2, 23, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 35, 19, 37, 2, 39, 2, 41, 2, 43, 20, 3, 2, 8, 3, 2, 41, 41, 4, 2, 48, 48, 97, 97, 3, 2, 99, 124, 3, 2, 67, 92, 3, 2, 50, 59, 5, 2, 11, 12, 15, 15, 34, 34, 2, 160, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 3, 45, 3, 2, 2, 2, 5, 47, 3, 2, 2, 2, 7, 49, 3, 2, 2, 2, 9, 52, 3, 2, 2, 2, 11, 54, 3, 2, 2, 2, 13, 61, 3, 2, 2, 2, 15, 71, 3, 2, 2, 2, 17, 82, 3, 2, 2, 2, 19, 84, 3, 2, 2, 2, 21, 100, 3, 2, 2, 2, 23, 106, 3, 2, 2, 2, 25, 114, 3, 2, 2, 2, 27, 116, 3, 2, 2, 2, 29, 118, 3, 2, 2, 2, 31, 120, 3, 2, 2, 2, 33, 123, 3, 2, 2, 2, 35, 127, 3, 2, 2, 2, 37, 138, 3, 2, 2, 2, 39, 140, 3, 2, 2, 2, 41, 142, 3, 2, 2, 2, 43, 145, 3, 2, 2, 2, 45, 46, 7, 63, 2, 2, 46, 4, 3, 2, 2, 2, 47, 48, 7, 64, 2, 2, 48, 6, 3, 2, 2, 2, 49, 50, 7, 64, 2, 2, 50, 51, 7, 63, 2, 2, 51, 8, 3, 2, 2, 2, 52, 53, 7, 62, 2, 2, 53, 10, 3, 2, 2, 2, 54, 55, 7, 62, 2, 2, 55, 56, 7, 63, 2, 2, 56, 12, 3, 2, 2, 2, 57, 58, 7, 62, 2, 2, 58, 62, 7, 64, 2, 2, 59, 60, 7, 35, 2, 2, 60, 62, 7, 63, 2, 2, 61, 57, 3, 2, 2, 2, 61, 59, 3, 2, 2, 2, 62, 14, 3, 2, 2, 2, 63, 64, 7, 110, 2, 2, 64, 65, 7, 107, 2, 2, 65, 66, 7, 109, 2, 2, 66, 72, 7, 103, 2, 2, 67, 68, 7, 78, 2, 2, 68, 69, 7, 75, 2, 2, 69, 70, 7, 77, 2, 2, 70, 72, 7, 71, 2, 2, 71, 63, 3, 2, 2, 2, 71, 67, 3, 2, 2, 2, 72, 16, 3, 2, 2, 2, 73, 74, 7, 118, 2, 2, 74, 75, 7, 116, 2, 2, 75, 76, 7, 119, 2, 2, 76, 83, 7, 103, 2, 2, 77, 78, 7, 104, 2, 2, 78, 79, 7, 99, 2, 2, 79, 80, 7, 110, 2, 2, 80, 81, 7, 117, 2, 2, 81, 83, 7, 103, 2, 2, 82, 73, 3, 2, 2, 2, 82, 77, 3, 2, 2, 2, 83, 18, 3, 2, 2, 2, 84, 88, 7, 41, 2, 2, 85, 89, 10, 2, 2, 2, 86, 87, 7, 41, 2, 2, 87, 89, 7, 41, 2, 2, 88, 85, 3, 2, 2, 2, 88, 86, 3, 2, 2, 2, 89, 90, 3, 2, 2, 2, 90, 88, 3, 2, 2, 2, 90, 91, 3, 2, 2, 2, 91, 92, 3, 2, 2, 2, 92, 93, 7, 41, 2, 2, 93, 20, 3, 2, 2, 2, 94, 95, 7, 99, 2, 2, 95, 96, 7, 112, 2, 2, 96, 101, 7, 102, 2, 2, 97, 98, 7, 67, 2, 2, 98, 99, 7, 80, 2, 2, 99, 101, 7, 70, 2, 2, 100, 94, 3, 2, 2, 2, 100, 97, 3, 2, 2, 2, 101, 22, 3, 2, 2, 2, 102, 103, 7, 113, 2, 2, 103, 107, 7, 116, 2, 2, 104, 105, 7, 81, 2, 2, 105, 107, 7, 84, 2, 2, 106, 102, 3, 2, 2, 2, 106, 104, 3, 2, 2, 2, 107, 24, 3, 2, 2, 2, 108, 109, 7, 112, 2, 2, 109, 110, 7, 113, 2, 2, 110, 115, 7, 118, 2, 2, 111, 112, 7, 80, 2, 2, 112, 113, 7, 81, 2, 2, 113, 115, 7, 86, 2, 2, 114, 108, 3, 2, 2, 2, 114, 111, 3, 2, 2, 2, 115, 26, 3, 2, 2, 2, 116, 117, 7, 42, 2, 2, 117, 28, 3, 2, 2, 2, 118, 119, 7, 43, 2, 2, 119, 30, 3, 2, 2, 2, 120, 121, 7, 48, 2, 2, 121, 32, 3, 2, 2, 2, 122, 124, 5, 41, 21, 2, 123, 122, 3, 2, 2, 2, 124, 125, 3, 2, 2, 2, 125, 123, 3, 2, 2, 2, 125, 126, 3, 2, 2, 2, 126, 34, 3, 2, 2, 2, 127, 136, 5, 37, 19, 2, 128, 131, 5, 37, 19, 2, 129, 131, 9, 3, 2, 2, 130, 128, 3, 2, 2, 2, 130, 129, 3, 2, 2, 2, 131, 134, 3, 2, 2, 2, 132, 130, 3, 2, 2, 2, 132, 133, 3, 2, 2, 2, 133, 135, 3, 2, 2, 2, 134, 132, 3, 2, 2, 2, 135, 137, 5, 37, 19, 2, 136, 132, 3, 2, 2, 2, 136, 137, 3, 2, 2, 2, 137, 36, 3, 2, 2, 2, 138, 139, 9, 4, 2, 2, 139, 38, 3, 2, 2, 2, 140, 141, 9, 5, 2, 2, 141, 40, 3, 2, 2, 2, 142, 143, 9, 6, 2, 2, 143, 42, 3, 2, 2, 2, 144, 146, 9, 7, 2, 2, 145, 144, 3, 2, 2, 2, 146, 147, 3, 2, 2, 2, 147, 145, 3, 2, 2, 2, 147, 148, 3, 2, 2, 2, 148, 149, 3, 2, 2, 2, 149, 150, 8, 22, 2, 2, 150, 44, 3, 2, 2, 2, 16, 2, 61, 71, 82, 88, 90, 100, 106, 114, 125, 130, 132, 136, 147, 3, 8, 2, 2]
Loading

0 comments on commit b91898a

Please sign in to comment.