Skip to content

Commit

Permalink
Ensure all non-breaking spaces and any other types of whitespace are …
Browse files Browse the repository at this point in the history
…replaced with regular spaces before performing .split on textarea wordcount
  • Loading branch information
DaniBitZesty committed Jul 16, 2024
1 parent 55f8649 commit 2daf1fa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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(/( |\n|\s)+/g, ' ').trim();
wordCount = normalizedContent.split(" ").length
if wordCount > wordLimit
@logThis(question, "validateWordLimit", "Word limit exceeded")
Expand Down

0 comments on commit 2daf1fa

Please sign in to comment.