From e7c1d28564d6dacd8e912e7f0251696ccff9dd16 Mon Sep 17 00:00:00 2001 From: Light Leung Date: Thu, 26 Jul 2018 21:09:45 +0800 Subject: [PATCH 1/6] Fix when the url value contains parentheses --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index df78325..ca2c8d8 100644 --- a/index.js +++ b/index.js @@ -34,8 +34,14 @@ function urldata(value){ while(value[start] === " "){ start++; } } - - end = value.indexOf(")", start); + if (!openQuote) { + end = value.indexOf(")", start); + } else { + end = start; + while(value[end] !== openQuote) { end++; } + while(value[end] !== ")"){ end++; } + } + if(end < 0){ return result; } @@ -55,4 +61,5 @@ function urldata(value){ } return result; } + module.exports = urldata; From 41b4c766f76eec32432448e77035be848c81079a Mon Sep 17 00:00:00 2001 From: Light Leung Date: Thu, 26 Jul 2018 21:12:34 +0800 Subject: [PATCH 2/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc28dc3..68fab6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urldata", - "version": "0.0.1", + "version": "0.0.2", "description": "Library to extract url data from css property", "main": "index.js", "repository": "lexich/urldata", From e6a5e81151461686fbc2babc307ca4cfd07a0ddf Mon Sep 17 00:00:00 2001 From: Light Leung Date: Thu, 26 Jul 2018 21:14:34 +0800 Subject: [PATCH 3/6] Update main_spec.js --- test/main_spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/main_spec.js b/test/main_spec.js index 0e10910..c000ba1 100644 --- a/test/main_spec.js +++ b/test/main_spec.js @@ -40,6 +40,11 @@ describe("urldata", function(){ urldata("url(\"images/test.png\")") ); }); + it("check urldata with parentheses", function(){ + ["(images/test.png)"].should.eql( + urldata("url(\"(images/test.png)\")") + ); + }); it("check urldata with wrong data", function(){ ["images/test.png\""].should.eql( urldata("url(images/test.png\")") From 9521038f03703a331e81ac75fce0257e61b10139 Mon Sep 17 00:00:00 2001 From: Light Date: Thu, 26 Jul 2018 22:51:04 +0800 Subject: [PATCH 4/6] parentheses bug fix --- index.js | 6 ++++-- package.json | 2 +- test/main_spec.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index ca2c8d8..023c1ba 100644 --- a/index.js +++ b/index.js @@ -38,12 +38,14 @@ function urldata(value){ end = value.indexOf(")", start); } else { end = start; - while(value[end] !== openQuote) { end++; } - while(value[end] !== ")"){ end++; } + while(value[end] !== openQuote && end < value.length) { end++; } + while(value[end] !== ")" && end < value.length){ end++; } } if(end < 0){ return result; + } else if (end === value.length) { + return result; } end--; while(value[end]===" "){ diff --git a/package.json b/package.json index 68fab6a..cf64729 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "repository": "lexich/urldata", "scripts": { - "test": "istanbul test _mocha --report html -- test/*.js --reporter spec", + "test": "istanbul test node_modules/mocha/bin/_mocha --report html -- test/*.js --reporter spec", "coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" }, "keywords": [ diff --git a/test/main_spec.js b/test/main_spec.js index c000ba1..5148985 100644 --- a/test/main_spec.js +++ b/test/main_spec.js @@ -49,7 +49,7 @@ describe("urldata", function(){ ["images/test.png\""].should.eql( urldata("url(images/test.png\")") ); - ["\' images/test.png"].should.eql( + [].should.eql( urldata("url( \' images/test.png)") ); }); From 2b353a8729ea0d00ad3158534f328b2f1a97676f Mon Sep 17 00:00:00 2001 From: Light Date: Thu, 26 Jul 2018 23:11:07 +0800 Subject: [PATCH 5/6] coverall rate --- package.json | 6 +++--- test/main_spec.js | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index cf64729..3165b27 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "repository": "lexich/urldata", "scripts": { "test": "istanbul test node_modules/mocha/bin/_mocha --report html -- test/*.js --reporter spec", - "coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" + "coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly --report html -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" }, "keywords": [ "node", @@ -18,9 +18,9 @@ "url": "https://github.com/lexich" }, "license": "MIT", - "dependencies": { - }, + "dependencies": {}, "devDependencies": { + "chai": "^4.1.2", "coveralls": "^2.11.2", "istanbul": "^0.3.2", "mocha": "^2.0.0", diff --git a/test/main_spec.js b/test/main_spec.js index 5148985..e38685b 100644 --- a/test/main_spec.js +++ b/test/main_spec.js @@ -1,7 +1,8 @@ /*global describe, it*/ "use strict"; var urldata = require("../"), - should = require("should"); + should = require("should"), + { expect } = require("chai"); describe("urldata", function(){ it("check urldata simple url", function(){ @@ -46,6 +47,10 @@ describe("urldata", function(){ ); }); it("check urldata with wrong data", function(){ + expect(urldata("")).to.be.undefined; + [].should.eql( + urldata("url") + ); ["images/test.png\""].should.eql( urldata("url(images/test.png\")") ); From 933854add4a3e98ee4f8f0182cfb104cfef19ee1 Mon Sep 17 00:00:00 2001 From: Light Date: Thu, 26 Jul 2018 23:31:44 +0800 Subject: [PATCH 6/6] lower version node compatibility --- test/main_spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/main_spec.js b/test/main_spec.js index e38685b..9c34418 100644 --- a/test/main_spec.js +++ b/test/main_spec.js @@ -2,7 +2,8 @@ "use strict"; var urldata = require("../"), should = require("should"), - { expect } = require("chai"); + chai = require("chai"), + expect = chai.expect; describe("urldata", function(){ it("check urldata simple url", function(){