Skip to content

Commit 3f79311

Browse files
committed
Correctly parse strings with extra spaces in front
1 parent f21367f commit 3f79311

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
module.exports = parse;
33

44
function parse(str) {
5-
return new Parser(str).parse();
5+
var cleanStr = str.replace(/^\s+|\s+$/, '');
6+
return new Parser(cleanStr).parse();
67
}
78

89
function Parser(str) {

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"name": "css-value",
33
"version": "0.0.1",
44
"description": "CSS value parser",
5-
"keywords": ["css", "parser", "value"],
5+
"keywords": [
6+
"css",
7+
"parser",
8+
"value"
9+
],
610
"author": "TJ Holowaychuk <tj@vision-media.ca>",
711
"repository": {
812
"type": "git",
@@ -13,5 +17,8 @@
1317
"mocha": "~1.9.0",
1418
"should": "~1.2.2"
1519
},
16-
"main": "index"
20+
"main": "index",
21+
"scripts": {
22+
"test": "mocha -r should"
23+
}
1724
}

test/cases/space-in-front.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
exports.string = ' rgba(1,2,3,4)';
2+
3+
exports.object = [
4+
{ type: 'color', value: 'rgba(1,2,3,4)' }
5+
]

test/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ var readdir = fs.readdirSync;
66
var path = require('path');
77
var basename = path.basename;
88

9-
readdir('test/cases').forEach(function(file){
9+
readdir('test/cases')
10+
.filter(function(fn) { return /\.js$/.test(fn); })
11+
.forEach(function(file){
1012
var mod = require(path.resolve('test/cases/' + file));
1113
var title = basename(file, '.js');
1214
it('should support ' + title, function(){

0 commit comments

Comments
 (0)