Skip to content

cel-go inherits RFC 3339 parsing bugs from Golang's time.Parse() #1108

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

Open
1 of 3 tasks
hudlow opened this issue Jan 17, 2025 · 1 comment
Open
1 of 3 tasks

cel-go inherits RFC 3339 parsing bugs from Golang's time.Parse() #1108

hudlow opened this issue Jan 17, 2025 · 1 comment

Comments

@hudlow
Copy link
Contributor

hudlow commented Jan 17, 2025

Describe the bug
cel-go inherits RFC 3339 parsing bugs from Golang's time.Parse()

To Reproduce
Check which components this affects:

  • parser
  • checker
  • interpreter

Sample expression and input that reproduces the issue:

(
  timestamp("2025-01-17T01:00:00.001Z") ==
  timestamp("2025-01-17T01:00:00,001Z") // comma-delimited fractional seconds
) &&
(
  timestamp("2025-01-17T01:00:00Z") ==
  timestamp("2025-01-17T1:00:00Z") // single-digit hour
) &&
(
  timestamp("2025-01-17T01:01:01.001+00:01") ==
  timestamp("2025-01-18T01:01:01.001+24:01") // offset > 24:00
) &&
(
  timestamp("2025-01-17T01:01:01.001+01:00") ==
  timestamp("2025-01-17T01:01:01.001+00:60") // offset minute > 59
)

Test setup:

package main

import (
  "fmt"
  "github.com/google/cel-go/cel"
)

func main() {
  env, _ := cel.NewEnv()
  ast, _ := env.Compile(`
    (
      timestamp("2025-01-17T01:00:00.001Z") ==
      timestamp("2025-01-17T01:00:00,001Z") // comma-delimited fractional seconds
    ) &&
    (
      timestamp("2025-01-17T01:00:00Z") ==
      timestamp("2025-01-17T1:00:00Z") // single-digit hour
    ) &&
    (
      timestamp("2025-01-17T01:01:01.001+00:01") ==
      timestamp("2025-01-18T01:01:01.001+24:01") // offset > 24:00
    ) &&
    (
      timestamp("2025-01-17T01:01:01.001+01:00") ==
      timestamp("2025-01-17T01:01:01.001+00:60") // offset minute > 59
    )
  `)
  prg, _ := env.Program(ast)
  out, _, _ := prg.Eval(map[string]any{})

  fmt.Println(out)
}

Expected behavior
Each of the latter examples should result in an error from the timestamp() function

Additional context
If compatibility is needed, I recommend we add an option in cel-go to provide compatibility rather than forcing other implementations to replicate Golang's bugs.

@TristonianJones
Copy link
Collaborator

Thanks, this is a good suggestion. I'm a little surprised that Golang has these bugs, but it's useful to know they're there.

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

2 participants