Giter Club home page Giter Club logo

filter-parser's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

filter-parser's Issues

SubAttribute Support

The filtering spec has this section: subAttr = "." ATTRNAME; a sub-attribute of a complex attribute. I determined I need to support a basic form of a PATCH endpoint and this is one scenario I was going to attempt to support in your wonderful SCIM library. Quick example:

parser := scim.NewParser(strings.NewReader("members[value eq \"whatever\"].displayName"))
filter, _ := parser.Parse() 

// filter ends up being:
AttributeExpression{
    AttributePath: "members.value",
    CompareOperator: "equal",
    CompareValue: "whatever",
}

Are you open to me adding a SubAttribute field to the AttributeExpression struct? Before doing any work I wanted your input, thanks in advance!

Attributenames starting with underscore

These filters cant be parsed
userType._id eq "Employee" parse: expected op.Or [0x1113820 0x1110500 0x11119c0 0x1111ca0] but got "u"
_userType eq "Employee" parse: expected op.Or [0x1113820 0x1110500 0x11119c0 0x1111ca0] but got "_"

From the RFC I understand it as it should be allowed:

     ATTRNAME  = ALPHA *(nameChar)

     nameChar  = "-" / "_" / DIGIT / ALPHA

Recommendations for traversing a parsed expression

I'm not sure how to traverse a parsed expression with version 2.1.1. For version 1.0.0 we could recurse through the Expression by

func walkExpression(e fp.Expression) error {
    switch stmt := e.(type) {
	case fp.UnaryExpression: 
		ex, err := walkExpression(stmt.X)
	case fp.BinaryExpression:
		ex, err := walkExpression(stmt.X)
		ey, err := walkExpression(stmt.Y)
	case fp.AttributeExpression:
		// verify/use the attribute
	case nil:
	default:
	}
}

Im not sure how to perform a similar operation with v2.1.1,
A similar technique with 2.1.1 gives me an error

	switch stmt := (e).(type) {
	case fp.LogicalExpression: <-

impossible type switch case: e (type filter.Expression) cannot have dynamic type filter.LogicalExpression (filter.exprNode method has pointer receiver)

Is there a recommended way to traverse the expression?

And thanks for the release earlier!

Filter - not able to parse _ and """"

If query is having filter like
filter=meta.resource_type eq "test" - fails

or

filter=meta co "W/"990-6468886345120203448"" - fails

filter with two inverted commas or underscore, it fails to parse.

Compare operator case sensitivity

In the https://tools.ietf.org/html/rfc7644#section-3.4.2.2
there is an example of the eq operator having the alternate casing Eq giving the same results.

Attribute names and attribute operators used in filters are case
   insensitive.  For example, the following two expressions will
   evaluate to the same logical value

   filter=userName Eq "john"
   filter=Username eq "john"

When I try this out I get the error
could not parse query: parse: expected op.Or [0x1c74b80 0x1c6ef20 0x1c71740 0x1c71d20] but got "u"

Bug: Precedence Operator

Precedence (brackets) seem to be ignored when parsing a filter like (ignore the non scim attributes):
expression := "( username eq \"test\" or request.path sw \"/finance\" ) and subject eq \"abc\""

Calling filter.ParseFilter([]byte(expression)) returns a filter.Expression result whose string value is:
username eq "test" or request.path sw "/finance" and subject eq "abc"

I have tried having spaces between brackets ("(") and content as well as no spaces.

I notice that the test does not actually validate the result, it just tests for no detected errors.

Support `json.Number`

We should (also) support returning json.Number instead of an int or float64, to prevent losing precision.

filter-parser/attrexp.go

Lines 121 to 133 in 47c4fd1

f, err := strconv.ParseFloat(nStr, 64)
if err != nil {
return AttributeExpression{}, &internalError{
Message: err.Error(),
}
}
// Integers can not contain fractional or exponent parts.
// More info: https://tools.ietf.org/html/rfc7643#section-2.3.4
if !frac && !exp {
return int(f), nil
}
return f, err

A filter expression that results in a stack overflow

The filter expression
name pr and not (first eq "test") and not (another eq "test")

parses into an expression with an really deep (inifinite?) LogicalExpression.Left chain.

and results in a stack overflow if printed

=== RUN   Test_Parsing/crashes?
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc0201e0578 stack=[0xc0201e0000, 0xc0401e0000]
fatal error: stack overflow

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.