Skip to content

Commit

Permalink
Make DomainNameRule.regex and DomainNameRule.validregex case-sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Jul 17, 2013
1 parent d4ae397 commit 16a814d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ __Arguments__
* `invalid` - An array of characters that are not allowed in the password (eg. `['!', '_']`)
* `required` - An array of characters where one of the characters needs to be in the password (eg. `['-', '!']`)
* `validregex` - A simplified regular expression that would fit in a character set (eg. `A-Z0-9`, which would fit in
`[A-Z0-9]`). The regular expression is run case-insensitively. `validregex` should be used in preference over
`[A-Z0-9]`). The regular expression is run case-sensitive. `validregex` should be used in preference over
`regex` (which can contain full regular expressions, not just a character sets), as `validregex` can easily
be inverted (eg `[^A-Z0-9]`) so passwords can be rewritten if they contain invalid characters.
* `regex` - A full regular expression that the password must match. The regex is run case-insensitively.
* `regex` - A full regular expression that the password must match. The regex is run case-sensitive.

__Returns__

Expand Down Expand Up @@ -318,4 +318,5 @@ The tests can also be run in a web browser:

* v0.1.0 - 2013-05-22: Initial version
* v0.2.0 - 2013-07-16: `DomainNameRule` and `standardizeDomain()` added.
* v0.2.1 - 2013-07-17: `DomainNameRule.validregex` added
* v0.2.1 - 2013-07-17: `DomainNameRule.validregex` added
* v0.2.2 - 2013-07-17: `DomainNameRule.validregex` and `DomainNameRule.regex` are case-sensitive now
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "SaltThePass.com algorithm",
"main": "./src/saltthepass",
"author": "Nic Jansma",
"version": "0.2.1",
"version": "0.2.2",
"repository" : {
"type" : "git",
"url" : "http://github.com/nicjansma/saltthepass.js.git"
Expand Down
6 changes: 3 additions & 3 deletions src/domainnamerule.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
return;
}

return new RegExp(this.regex, 'i');
return new RegExp(this.regex);
};

/**
Expand All @@ -307,9 +307,9 @@
}

if (reverse) {
return new RegExp('[^' + this.validregex + ']', 'gi');
return new RegExp('[^' + this.validregex + ']', 'g');
} else {
return new RegExp('^[' + this.validregex + ']+$', 'i');
return new RegExp('^[' + this.validregex + ']+$');
}
};

Expand Down
52 changes: 49 additions & 3 deletions test/domainnamerule.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
testcases['.isValid() - validregex'] = function(test) {
var dnr = new DomainNameRule({
domain: 'foo.com',
validregex: 'A-Z0-9'
validregex: 'A-Za-z0-9'
});

// true
Expand All @@ -153,6 +153,34 @@
test.done();
};

testcases['.isValid() - validregex - case sensitive'] = function(test) {
var dnr = new DomainNameRule({
domain: 'foo.com',
validregex: 'A-Z0-9'
});

// true
test.ok(dnr.isValid('A'));
test.ok(dnr.isValid('AA'));

// not valid per case sensitivity
test.ok(!dnr.isValid('aA9'));
test.ok(!dnr.isValid('aA1z091AZfa'));
test.ok(!dnr.isValid('a'));
test.ok(!dnr.isValid('aa'));
test.ok(!dnr.isValid('a9'));
test.ok(!dnr.isValid('aa01asd12e12d'));

// not valid per regex
test.ok(!dnr.isValid('a-'));
test.ok(!dnr.isValid('a.'));
test.ok(!dnr.isValid('a?'));
test.ok(!dnr.isValid('-'));
test.ok(!dnr.isValid('a-a'));

test.done();
};

testcases['.isValid() - regex'] = function(test) {
var dnr = new DomainNameRule({
domain: 'foo.com',
Expand Down Expand Up @@ -235,7 +263,7 @@
testcases['.rewrite() - validregex'] = function(test) {
var dnr = new DomainNameRule({
domain: 'foo.com',
validregex: 'A-Z0-9'
validregex: 'A-Za-z0-9'
});

// no change - good
Expand All @@ -250,4 +278,22 @@

test.done();
};
})(exports);

testcases['.rewrite() - validregex - case sensitivity'] = function(test) {
var dnr = new DomainNameRule({
domain: 'foo.com',
validregex: 'A-Z0-9'
});

// no change - good
test.equal('PSS', dnr.rewrite('PaSS'));
test.equal('PASS', dnr.rewrite('PASS'));
test.equal('PASS01', dnr.rewrite('PASS01'));

// remove invalid chars
test.equal('PASSPASS', dnr.rewrite('PASS-PASS'));
test.equal('PASSPASS', dnr.rewrite('PASS?-PASS'));
test.equal('PASS', dnr.rewrite('pass?-PASS'));

test.done();
};})(exports);

0 comments on commit 16a814d

Please sign in to comment.