Skip to content

Commit d70e191

Browse files
Merge pull request #27 from CiscoM31/empty-token
Fix tokenization of empty token
2 parents 160812b + 6cad311 commit d70e191

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

filter_parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ func FilterTokenizer() *Tokenizer {
146146
func unescapeTokenString(in string) string {
147147
// The call to ReplaceAll() implements
148148
// SQUOTE-in-string = SQUOTE SQUOTE ; two consecutive single quotes represent one within a string literal
149+
if in == "''" {
150+
return in
151+
}
149152
return strings.ReplaceAll(in, "''", "'")
150153
}
151154

filter_parser_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,24 @@ func TestFilterNotBooleanProperty(t *testing.T) {
457457

458458
}
459459

460+
func TestFilterEmptyStringToken(t *testing.T) {
461+
tokenizer := FilterTokenizer()
462+
input := "City eq ''"
463+
expect := []*Token{
464+
{Value: "City", Type: FilterTokenLiteral},
465+
{Value: "eq", Type: FilterTokenLogical},
466+
{Value: "''", Type: FilterTokenString},
467+
}
468+
output, err := tokenizer.Tokenize(input)
469+
if err != nil {
470+
t.Error(err)
471+
}
472+
result, err := CompareTokens(expect, output)
473+
if !result {
474+
t.Error(err)
475+
}
476+
}
477+
460478
// Note: according to ODATA ABNF notation, there must be a space between not and open parenthesis.
461479
// http://docs.oasis-open.org/odata/odata/v4.01/csprd03/abnf/odata-abnf-construction-rules.txt
462480
func TestFilterNotWithNoSpace(t *testing.T) {

0 commit comments

Comments
 (0)