Skip to content

Commit aa0d624

Browse files
jamierytlewskijzaefferer
authored andcommitted
Methods: Adding Smart Quotes to stripHTML's punctuation removal
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
1 parent f93e1de commit aa0d624

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/additional/additional.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// remove html tags and space chars
1515
return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' ')
1616
// remove punctuation
17-
.replace(/[.(),;:!?%#$'"_+=\/\-]*/g,'');
17+
.replace(/[.(),;:!?%#$'"_+=\/\-]*/g,'');
1818
}
1919

2020
jQuery.validator.addMethod("maxWords", function(value, element, params) {

test/methods.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,4 +1132,37 @@ test("cifES", function() {
11321132
ok(!method( "B-43.522.192" ), "CIF invalid: dots and dash" );
11331133
});
11341134

1135+
test("maxWords", function(){
1136+
var method = methodTest("maxWords");
1137+
var maxWords = 6;
1138+
ok( method( "I am a sentence", maxWords), "Max Words");
1139+
ok(!method( "I'm way too long for this sentence!", maxWords), "Too many words");
1140+
ok(method( "Don’t “count” me as too long", maxWords), "Right amount of words with smartquotes");
1141+
ok(!method( "But you can “count” me as too long", maxWords), "Too many words with smartquotes");
1142+
ok(method( "<div>Don’t “count” me as too long</div>", maxWords), "Right amount of words with smartquotes w/ HTML");
1143+
ok(!method( "<div>But you can “count” me as too long</div>", maxWords), "Too many words with smartquotes w/ HTML");
1144+
});
1145+
1146+
test("minWords", function(){
1147+
var method = methodTest("minWords");
1148+
var minWords = 6;
1149+
ok(!method( "I am a short sentence", minWords), "Max Words");
1150+
ok( method( "I'm way too long for this sentence!", minWords), "Too many words");
1151+
ok(!method( "Don’t “count” me as short.", minWords), "Right amount of words with smartquotes");
1152+
ok( method( "But you can “count” me as too short", minWords), "Too many words with smartquotes");
1153+
ok(!method( "<div>“Count” me as too short.</div>", minWords), "Right amount of words with smartquotes w/ HTML");
1154+
ok( method( "<div>But you can “count” me as too long</div>", minWords), "Too many words with smartquotes w/ HTML");
1155+
});
1156+
1157+
test("rangeWords", function(){
1158+
var method = methodTest("rangeWords");
1159+
var rangeWords = [3,6];
1160+
ok(!method( "I'm going to be longer than “six words!”", rangeWords), "Longer than 6 with smartquotes");
1161+
ok( method( "I'm just the right amount!", rangeWords), "In between");
1162+
ok( method( "Super short sentence’s.", rangeWords), "Low end");
1163+
ok(!method( "I", rangeWords), "Too short");
1164+
ok( method( "<div>“Count” me as perfect.</div>", rangeWords), "Right amount of words with smartquotes w/ HTML");
1165+
ok(!method( "<div>But you can “count” me as too long</div>", rangeWords), "Too many words with smartquotes w/ HTML");
1166+
});
1167+
11351168
})(jQuery);

0 commit comments

Comments
 (0)