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

Ensure all non-breaking spaces and any other types of whitespace are replaced with regular spaces before performing .split on textarea wordcount #3003

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

DaniBitZesty
Copy link
Contributor

📝 A short description of the changes

  • Ensure all non-breaking spaces and any other types of whitespace are replaced with regular spaces before performing .split on textarea wordcount

🔗 Link to the relevant story (or stories)

:shipit: Deployment implications

✅ Checklist

  • Features that cannot go live are behind a feature flag/env var or specify deploy date and open PR as draft
  • I have checked that commit messages make sense and explain the reasoning for each change
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have squashed any unnecessary or part-finished commits

🖼️ Screenshots (if appropriate - no PII/Prod data):

@@ -140,7 +140,8 @@ window.FormValidation =
validateWordLimit: (question) ->
textarea = question.find("textarea")
wordLimit = textarea.attr("data-word-max")
normalizedContent = textarea.val().replace(/ /g, ' ').replace(/\n/g, ' ');
textareaValue = textarea.val() || '';
normalizedContent = textareaValue.replace(/ /g, ' ').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

you optimise this... use one regex with array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.replace(/( |\n|\s)+/g, ' ').trim(); is better @saenom ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. It's more readable. thanks!

…replaced with regular spaces before performing .split on textarea wordcount
@DaniBitZesty DaniBitZesty merged commit a6d9bbb into main Jul 16, 2024
11 checks passed
@DaniBitZesty DaniBitZesty deleted the textarea branch July 16, 2024 13:20
@TheDancingClown TheDancingClown mentioned this pull request Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants