Skip to content

Commit

Permalink
fix: avoid key to start with $ sign (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-serafin authored Oct 27, 2018
1 parent 0faa4e2 commit 2f175fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions filterparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ func (p *FilterParser) parseOperatorAndValue() (parserToken, interface{}, error)

func (p *FilterParser) makeFilter(key string, operator parserToken, value interface{}) (*Filter, error) {

if strings.HasPrefix(key, "$") {
return nil, fmt.Errorf("could not start a parameter with $. Found %s", key)
}

filter := NewFilterComposer()

// Create filter
Expand Down
10 changes: 5 additions & 5 deletions filterparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,16 @@ func TestParser_Keys(t *testing.T) {
Convey("Given the expression is a tag like '$key'", t, func() {

parser := NewFilterParser("$key == value")
expectedFilter := NewFilterComposer().WithKey("$key").Equals("value").Done()
// expectedFilter := NewFilterComposer().WithKey("$key").Equals("value").Done()

Convey("When I run Parse", func() {

filter, err := parser.Parse()

Convey("Then there should be no error and the filter should as expected", func() {
So(err, ShouldEqual, nil)
So(filter, ShouldNotEqual, nil)
So(filter.String(), ShouldEqual, expectedFilter.String())
Convey("Then there should have an error", func() {
So(err, ShouldNotEqual, nil)
So(err.Error(), ShouldContainSubstring, "could not start a parameter with $")
So(filter, ShouldEqual, nil)
})
})
})
Expand Down

0 comments on commit 2f175fc

Please sign in to comment.