Skip to content

Commit

Permalink
Fix issue #8 Accented characters were converting to upper case when c…
Browse files Browse the repository at this point in the history
…apitalize modifier is used.

\W is Matches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_].

Support for internationalization in JavaScript's RegExp is virtually nonexistent.

Convert \W to its equivalent with including accented chars

Reference:
http://compgroups.net/comp.lang.javascript/regex-with-accents/190205
http://stackoverflow.com/questions/5436824/matching-accented-characters-with-javascript-regexes
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp#character-sets

Issue raised: #8
  • Loading branch information
Uma committed Dec 25, 2014
1 parent bbfd49d commit 877d340
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions jsmart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2988,11 +2988,13 @@
jSmart.prototype.registerPlugin(
'modifier',
'capitalize',
function(s, withDigits)
{
var re = new RegExp(withDigits ? '[\\W\\d]+' : '\\W+');
function(s, upDigits, lcRest) {
var re = new RegExp(upDigits ? '[^a-zA-Z_\u00E0-\u00FC]+' : '[^a-zA-Z0-9_\u00E0-\u00FC]');
var found = null;
var res = '';
if (lcRest) {
s = s.toLowerCase();
}
for (found=s.match(re); found; found=s.match(re))
{
var word = s.slice(0,found.index);
Expand Down
4 changes: 3 additions & 1 deletion test/templates/modifiers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Long text with line breaks converted to BRs [{$long_text|nl2br}]

{"next x-men film, x3, delayed last7"|capitalize}
{"next x-men film, x3, delayed last7"|capitalize:true}
{"next x-MeN film, x3, delaYED last7"|capitalize:true:true}
{"next x-MeN film, x3, delaYED last7"|capitalize:true}

{"1st num8er 3x 3zz 3numbers1n1word"|capitalize:true} {*"3numbers1n1word"|capitalize - Smarty renders this capitalized, bug?*}

Expand Down Expand Up @@ -112,4 +114,4 @@ Long text with line breaks converted to BRs [{$long_text|nl2br}]
{$arr|count}
{$pers = ['name'=>['first'=>'John','last'=>'Doe'],'age'=>36]}
{$pers|count}
{$pers|count:1}
{$pers|count:1}

0 comments on commit 877d340

Please sign in to comment.