Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In some cases "rules" can parse with dots/hyphens/etc in name #2200

Closed
patrick-east opened this issue Mar 20, 2020 · 0 comments · Fixed by #2219
Closed

In some cases "rules" can parse with dots/hyphens/etc in name #2200

patrick-east opened this issue Mar 20, 2020 · 0 comments · Fixed by #2219
Labels

Comments

@patrick-east
Copy link
Contributor

Expected Behavior

A rule defined like:

package example

foo.bar = x {
    x := 123
}

Should raise a parse error. This isn't a valid rule name.. Same goes for..

package example

foo-bar = x {
    x := 123
}

And some others (can toss in + and more in there)

Actual Behavior

The "rule" parses... but isn't what the author probably intended. What you get is:

$ opa eval -d /tmp/x.rego -f pretty 'data'
{
  "example": {
    "foo": {
      "bar": 123
    },
    "x": 123
  }
}

😞

Additional Info

Whats happening is that it is being parsed with a partial rule like foo[bar] = x { true } and a rule defined with wrapping braces (see #2199) of x = 123 { true }.

{
  "package": {
    "path": [
      {
        "type": "var",
        "value": "data"
      },
      {
        "type": "string",
        "value": "example"
      }
    ]
  },
  "rules": [
    {
      "head": {
        "name": "foo",
        "key": {
          "type": "string",
          "value": "bar"
        },
        "value": {
          "type": "var",
          "value": "x"
        }
      },
      "body": [
        {
          "index": 0,
          "terms": {
            "type": "boolean",
            "value": true
          }
        }
      ]
    },
    {
      "head": {
        "name": "x",
        "value": {
          "type": "number",
          "value": 123
        },
        "assign": true
      },
      "body": [
        {
          "index": 0,
          "terms": {
            "type": "boolean",
            "value": true
          }
        }
      ]
    }
  ]
}
@patrick-east patrick-east changed the title In some cases "rules" can parse with dots/hypens/etc in name In some cases "rules" can parse with dots/hyphens/etc in name Mar 23, 2020
tsandall added a commit to tsandall/opa that referenced this issue Mar 25, 2020
This commit replaces the existing PEG generated parser with a parser
implemented by hand. The new parser is more efficient (avoiding old
problems with pathological input cases like {{{{{{{{{}}}}}}}} and
deeply-nested composites in general) and offers better opportunities
for improved error reporting (which has been improved already but
there is still room to grow.)

During the test process of implementing the new parser, we identified
a few issues that were present in the old parser. Those issues are
fixed by this commit.

Fixes open-policy-agent#1251
Fixes open-policy-agent#501
Fixes open-policy-agent#2198
Fixes open-policy-agent#2199
Fixes open-policy-agent#2200
Fixes open-policy-agent#2201
Fixes open-policy-agent#2202
Fixes open-policy-agent#2203

Co-authored-by: Torin Sandall <torinsandall@gmail.com>
Co-authored-by: Patrick East <east.patrick@gmail.com>

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Patrick East <east.patrick@gmail.com>
tsandall added a commit that referenced this issue Mar 26, 2020
This commit replaces the existing PEG generated parser with a parser
implemented by hand. The new parser is more efficient (avoiding old
problems with pathological input cases like {{{{{{{{{}}}}}}}} and
deeply-nested composites in general) and offers better opportunities
for improved error reporting (which has been improved already but
there is still room to grow.)

During the test process of implementing the new parser, we identified
a few issues that were present in the old parser. Those issues are
fixed by this commit.

Fixes #1251
Fixes #501
Fixes #2198
Fixes #2199
Fixes #2200
Fixes #2201
Fixes #2202
Fixes #2203

Co-authored-by: Torin Sandall <torinsandall@gmail.com>
Co-authored-by: Patrick East <east.patrick@gmail.com>

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Patrick East <east.patrick@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant