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

Question: escaping keywords #1059

Open
matthchr opened this issue Oct 31, 2024 · 1 comment
Open

Question: escaping keywords #1059

matthchr opened this issue Oct 31, 2024 · 1 comment

Comments

@matthchr
Copy link
Contributor

matthchr commented Oct 31, 2024

I'm doing something similar to Kubernetes, using CEL for validation. One of the things Kubernetes does is define escaping rules. These rules are (as far as I can tell) specifically for property names, which makes sense because the authors of CEL expressions can control what they name things (they know they're writing CEL), but when referring to OpenAPI objects the properties are what they are, but may not be CEL-compatible because CEL doesn't support -, /, or . in property names while OpenAPI does.

I'm curious about the __{keyword}__ escapes though. I've done a bunch of testing and there are definitely some reserved keywords that you have to escape in a CEL expression: self.true and self.false don't work, but many others like self.namespace and self.break seem to work fine, at least with the Env I've configured. Kubernetes escapes these anyway though, including namespace which is very commonly used.

My question is:
Is there actual guidance on what keywords need to be escaped and which don't? Especially in context of struct fields?

Kubernetes just used a hammer and escaped them all, but .namespace seems to actually work. Since it works, I think you couldn't just suddenly make it stop working as you'd break existing expressions. .break, .const (and various others) also seem to work fine.

@matthchr
Copy link
Contributor Author

matthchr commented Oct 31, 2024

Possibly you actually explain this in the CEL spec: https://github.com/google/cel-spec/blob/master/doc/langdef.md#syntax

The following identifiers are reserved due to their use as literal values or in the syntax:
false in null true

The following identifiers are reserved to allow easier embedding of CEL into a host language.
as break const continue else for function if import let loop package
namespace return var void while

Which maybe is saying: "If you're not talking about an embedding, you need to escape false, in, null, true ONLY" - am I interpreting that right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant