#trim() doesn't work where "\s" is present #108

diversario opened this Issue Aug 30, 2012 · 3 comments


None yet
2 participants

In filter.test.js, adding a line

assert.equal('abc', Filter.sanitize('   \s\r\n  abc\r\n   ').trim());

causes test to fail with

AssertionError: "abc" == "s\r\n  abc"

This came up when I tried to run a line from the module description:

var str = sanitize(' \s\t\r hello \n').trim();       //'hello'

Node 0.8.5, validator v0.4.11, Ubuntu 12.04.


chriso commented Sep 24, 2012

\s isn't recognised as a character replacement in Javascript; it's a regular expression directive representing whitespace. The native String.prototype.trim() will return the same results

/^\s+$/.test('\r\n\t'); // => true
/^\s+$/.test('\r\n\t\s'); // => false
'\r\n\sfoo'.trim() => 'sfoo'
'\s\r\nfoo'.trim() => 's\r\nfoo'

chriso closed this Sep 24, 2012

Right, so the example is incorrect.

@chriso chriso added a commit that referenced this issue Sep 25, 2012

@chriso chriso Fix example, re #108 531b880

chriso commented Sep 25, 2012

Ah I see, fixed thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment