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

customcommands: align frontend length display with backend validation #1710

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

jo3-l
Copy link
Contributor

@jo3-l jo3-l commented Jul 29, 2024

The backend validation for custom command response length checks the number of runes (that is, Unicode code points) in the input:

combinedSize += utf8.RuneCountInString(v)

However, the frontend character counter reads the length field of the response JavaScript String, which measures UTF-16 code units. The number of Unicode code points is not necessarily equal to the number of UTF-16 code units, occasionally producing a confusing discrepancy between frontend and backend. To demonstrate the issue, create a new custom command and run the following in console:

$('.cc-editor').val('😨'.repeat(5001)); // 😨 is encoded as 2 UTF-16 code units but is one code point
onCCChanged(); 

The character counter displays 10002/10000 (seemingly over the limit!) but this custom command can still be saved without error, since the backend validation only sees 5001 runes.

Fix this discrepancy by counting Unicode code points in the frontend as well.

@ashishjh-bst ashishjh-bst merged commit 2fb3cfb into botlabs-gg:dev Jul 30, 2024
1 check 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.

2 participants