Skip to content

Commit 9935d94

Browse files
committed
Validated option values
1 parent 4b5d775 commit 9935d94

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

lib/csscomb.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ Comb.prototype = {
3333
if (config.hasOwnProperty(option) && config[option] && this._options[option]) {
3434
var handler;
3535
try {
36-
handler = require('./options/' + option);
37-
handler.value = config[option];
38-
this._config[option] = handler;
36+
this._config[option] = require('./options/' + option).setValue(config[option]);
3937
} catch (e) {}
4038
}
4139
}

lib/options/colon-space.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
module.exports = {
22

3-
value: false,
3+
_value: false,
4+
5+
/**
6+
* Sets handler value.
7+
*
8+
* @param {String|Boolean} value Option value
9+
* @returns {Object}
10+
*/
11+
setValue: function(value) {
12+
if (!value) return this;
13+
if (typeof value === 'string') {
14+
this._value = value;
15+
} else {
16+
this._value = 'after'; // default
17+
}
18+
return this;
19+
},
420

521
/**
622
* Processes tree node.
@@ -10,12 +26,12 @@ module.exports = {
1026
process: function(nodeType, node) {
1127
if (nodeType === 'property') {
1228
if (node[node.length - 1][0] === 's') node.pop();
13-
if (this.value === 'both' || this.value === 'before')
29+
if (this._value === 'both' || this._value === 'before')
1430
node.push(['s', ' ']);
1531
}
1632
if (nodeType === 'value') {
1733
if (node[0][0] === 's') node.shift();
18-
if (this.value === 'both' || this.value === 'after')
34+
if (this._value === 'both' || this._value === 'after')
1935
node.unshift(['s', ' ']);
2036
}
2137
}

lib/options/strip-spaces.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ module.exports = {
22

33
value: false,
44

5+
/**
6+
* Sets handler value.
7+
*
8+
* @param {String|Boolean} value Option value
9+
* @returns {Object}
10+
*/
11+
setValue: function(value) {
12+
this._value = !!value;
13+
return this;
14+
},
15+
516
/**
617
* Processes tree node.
718
* @param {String} nodeType

0 commit comments

Comments
 (0)