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

Strings::split incompatibility for empty delimiters #291

Closed
codido opened this issue Jul 30, 2024 · 2 comments · Fixed by #295
Closed

Strings::split incompatibility for empty delimiters #291

codido opened this issue Jul 30, 2024 · 2 comments · Fixed by #295

Comments

@codido
Copy link

codido commented Jul 30, 2024

OPA and Regorus evaluate split differently when empty delimiters are
used.

In particular, the OPA implementation seems to follow the Go
strings.Split definition ("If sep is empty, Split splits after each
UTF-8 sequence"). In comparison, Regorus uses str::split, which also
returns the beginning and end of the string.

For example:

$ opa eval 'split("test", "")'
{
  "result": [
    {
      "expressions": [
        {
          "value": [
            "t",
            "e",
            "s",
            "t"
          ],
          "text": "split(\"test\", \"\")",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ]
}

vs.

$ regorus eval 'split("test", "")'
{
  "result": [
    {
      "expressions": [
        {
          "value": [
            "",
            "t",
            "e",
            "s",
            "t",
            ""
          ],
          "text": "split(\"test\", \"\")",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ]
}
@anakrish
Copy link
Collaborator

anakrish commented Aug 8, 2024

@codido Thanks for reporting this! This scenario is not covered by the OPA test suite and I've added a test locking it down in the Regorus repository.

@codido
Copy link
Author

codido commented Aug 8, 2024

@anakrish Thank you!

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

Successfully merging a pull request may close this issue.

2 participants