Skip to content

Commit

Permalink
Methods: Adding Smart Quotes to stripHTML's punctuation removal
Browse files Browse the repository at this point in the history
Addresses an issue with the word count where smart quotes were not
removed, but the word count counted the words as the punctuation was not
removed.

Closes gh-811
  • Loading branch information
jamierytlewski authored and jzaefferer committed Jan 14, 2014
1 parent f93e1de commit aa0d624
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/additional/additional.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// remove html tags and space chars
return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' ')
// remove punctuation
.replace(/[.(),;:!?%#$'"_+=\/\-]*/g,'');
.replace(/[.(),;:!?%#$'"_+=\/\-“”’]*/g,'');
}

jQuery.validator.addMethod("maxWords", function(value, element, params) {
Expand Down
33 changes: 33 additions & 0 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -1132,4 +1132,37 @@ test("cifES", function() {
ok(!method( "B-43.522.192" ), "CIF invalid: dots and dash" );
});

test("maxWords", function(){
var method = methodTest("maxWords");
var maxWords = 6;
ok( method( "I am a sentence", maxWords), "Max Words");
ok(!method( "I'm way too long for this sentence!", maxWords), "Too many words");
ok(method( "Don’t “count” me as too long", maxWords), "Right amount of words with smartquotes");
ok(!method( "But you can “count” me as too long", maxWords), "Too many words with smartquotes");
ok(method( "<div>Don’t “count” me as too long</div>", maxWords), "Right amount of words with smartquotes w/ HTML");
ok(!method( "<div>But you can “count” me as too long</div>", maxWords), "Too many words with smartquotes w/ HTML");
});

test("minWords", function(){
var method = methodTest("minWords");
var minWords = 6;
ok(!method( "I am a short sentence", minWords), "Max Words");
ok( method( "I'm way too long for this sentence!", minWords), "Too many words");
ok(!method( "Don’t “count” me as short.", minWords), "Right amount of words with smartquotes");
ok( method( "But you can “count” me as too short", minWords), "Too many words with smartquotes");
ok(!method( "<div>“Count” me as too short.</div>", minWords), "Right amount of words with smartquotes w/ HTML");
ok( method( "<div>But you can “count” me as too long</div>", minWords), "Too many words with smartquotes w/ HTML");
});

test("rangeWords", function(){
var method = methodTest("rangeWords");
var rangeWords = [3,6];
ok(!method( "I'm going to be longer than “six words!”", rangeWords), "Longer than 6 with smartquotes");
ok( method( "I'm just the right amount!", rangeWords), "In between");
ok( method( "Super short sentence’s.", rangeWords), "Low end");
ok(!method( "I", rangeWords), "Too short");
ok( method( "<div>“Count” me as perfect.</div>", rangeWords), "Right amount of words with smartquotes w/ HTML");
ok(!method( "<div>But you can “count” me as too long</div>", rangeWords), "Too many words with smartquotes w/ HTML");
});

})(jQuery);

0 comments on commit aa0d624

Please sign in to comment.