Git Product home page Git Product logo

Comments (3)

charithe avatar charithe commented on May 29, 2024

Do you have an example of this? I can't reproduce it.

from cerbos.

charithe avatar charithe commented on May 29, 2024

OK, managed to reproduce it. It looks like the fold operator (>) removes the last character of the string regardless of whether it's a newline or not. Curiously, the literal operator (|) doesn't have this problem.

If you have a very aggressive editor that removes all line feeds from the end of the file, then you'd run into this issue. Mine is configured to remove all trailing spaces too but it's not so aggressive as to remove the line feed at the end of the line. I had to explicitly truncate the last byte using truncate -s -1 file.yaml to reproduce this problem.

This fails because there's no line feed at the end.

apiVersion:·api.cerbos.dev/v1␊
resourcePolicy:␊
··version:·"default"␊
··resource:·"foo"␊
··rules:␊
····-·actions:·[·'view'·]␊
······effect:·EFFECT_ALLOW␊
······roles:·[·'user'·]␊
······condition:␊
········match:␊
··········expr:·>␊
············R.attr.accountId·==·P.attr.accountId·&&␊
············(␊
··············(R.attr.creatorId·==·P.id·&&·R.attr.status·==·"draft")·||␊
··············(has(P.attr.roles.admin)·&&·R.attr.creator.orgUnitIds·in·P.attr.roles.admin)·||␊
··············(R.attr.type·==·"organizational"·&&·R.attr.status·==·"published")␊
············)

Notice that the final bracket is missing from the expression. Which means that the > operator must have removed it.

Invalid expression: `R.attr.accountId == P.attr.accountId && (   (R.attr.creatorId == P.id && R.attr.status == "draft") ||   (has(P.attr.roles.admin) && R.attr.creator.orgUnitIds in P.attr.roles.admin) ||   (R.attr.type == "organizational" && R.attr.status == "published")` <failed to compile `R.attr.accountId == P.attr.accountId && (   (R.attr.creatorId == P.id && R.attr.status == "draft") ||   (has(P.attr.roles.admin) && R.attr.creator.orgUnitIds in P.attr.roles.admin) ||   (R.attr.type == "organizational" && R.attr.status == "published")` [Syntax error: missing ')' at '<EOF>']>

This works because there's a line feed after the last bracket.

apiVersion:·api.cerbos.dev/v1␊
resourcePolicy:␊
··version:·"default"␊
··resource:·"foo"␊
··rules:␊
····-·actions:·[·'view'·]␊
······effect:·EFFECT_ALLOW␊
······roles:·[·'user'·]␊
······condition:␊
········match:␊
··········expr:·>␊
············R.attr.accountId·==·P.attr.accountId·&&␊
············(␊
··············(R.attr.creatorId·==·P.id·&&·R.attr.status·==·"draft")·||␊
··············(has(P.attr.roles.admin)·&&·R.attr.creator.orgUnitIds·in·P.attr.roles.admin)·||␊
··············(R.attr.type·==·"organizational"·&&·R.attr.status·==·"published")␊
············)␊

The | operator doesn't have this issue even if there's no line feed at the end. This works just fine.

apiVersion:·api.cerbos.dev/v1␊
resourcePolicy:␊
··version:·"default"␊
··resource:·"foo"␊
··rules:␊
····-·actions:·[·'view'·]␊
······effect:·EFFECT_ALLOW␊
······roles:·[·'user'·]␊
······condition:␊
········match:␊
··········expr:·|␊
············R.attr.accountId·==·P.attr.accountId·&&␊
············(␊
··············(R.attr.creatorId·==·P.id·&&·R.attr.status·==·"draft")·||␊
··············(has(P.attr.roles.admin)·&&·R.attr.creator.orgUnitIds·in·P.attr.roles.admin)·||␊
··············(R.attr.type·==·"organizational"·&&·R.attr.status·==·"published")␊
············)

I'll look into why > is doing this. In the mean time, the solution is to use the | operator.

from cerbos.

charithe avatar charithe commented on May 29, 2024

goccy/go-yaml#434

from cerbos.

Related Issues (20)

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.