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

Enhanced String Length Handling #426

Conversation

elliotmjackson
Copy link
Contributor

@elliotmjackson elliotmjackson commented Jul 9, 2023

This PR introduces improvements to the way string length is handled. The existing String.length() method has limitations, and this proposal suggests alternative models for more accurate results. By considering Unicode codepoints and multilingual text, developers can achieve greater flexibility and precision.

@snazy
Copy link
Member

snazy commented Jul 10, 2023

Generally no concerns about adding such a functionality. However, this change breaks existing behavior. It would be fine to add it as a new function.

@elliotmjackson
Copy link
Contributor Author

Thanks for your quick reply! I totally see your point about not breaking current behavior. I just wanted to mention that the Java and Go CEL implementations handle string lengths differently, causing potential confusion.

Happy to add this as a new function. Could you give me some pointers on that?

@snazy
Copy link
Member

snazy commented Jul 10, 2023

So Go's string-length works differently? Interesting.
I found this issue, which updates the CEL spec to talk about string-length vs. code-points, so I suspect your current change makes CEL-Java's string-length conformant to the CEL spec. I think, that classifies this PR as a legit bug fix, which then justifies the change in behavior.

Could you add some test-cases to validate the behavior?

@elliotmjackson
Copy link
Contributor Author

sure can, thanks for your thoughtful consideration.

@Test
void stringSizeEmoji() {
assertThat(stringOf("").size()).isSameAs(IntZero);
assertThat(stringOf("\uD83D\uDE05\uD83D\uDE04\uD83D\uDC7E").size()).isEqualTo(intOf(3));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is equal to "😅😄👾"

@snazy snazy merged commit a4ff894 into projectnessie:main Jul 11, 2023
4 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants