Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.

Commit 3445d3b

Browse files
committed
Validate the provided url
1 parent 1874752 commit 3445d3b

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
var q = require('q');
44
var isCss = require('is-css');
5+
var isBlank = require('is-blank')
6+
var isUrl = require('is-url-superb')
57
var request = require('request');
68
var cheerio = require('cheerio');
79
var normalizeUrl = require('normalize-url');
@@ -20,6 +22,10 @@ module.exports = function(url, options){
2022
options.timeout = options.timeout || 5000;
2123
options.gzip = true;
2224

25+
if (typeof url !== 'string' || isBlank(url) || !isUrl(url)) {
26+
throw new TypeError('get-css expected a url as a string')
27+
}
28+
2329
url = normalizeUrl(url, { stripWWW: false });
2430
options.url = url;
2531

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"dependencies": {
1515
"cheerio": "^0.19.0",
1616
"commander": "^2.7.1",
17+
"is-blank": "^1.0.0",
1718
"is-css": "^1.0.0",
19+
"is-url-superb": "^2.0.0",
1820
"normalize-url": "^1.2.0",
1921
"q": "^1.1.2",
2022
"request": "^2.48.0",

0 commit comments

Comments
 (0)