Skip to content

Commit 1d19820

Browse files
committed
Revert "Remove excess code"
This reverts commit b3e4bf7.
1 parent b91505f commit 1d19820

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

lib/config/defaults.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var config = {
22
defaultFilename: 'index.html',
3+
log: false,
34
sources: [
45
{
56
selector: 'img',
@@ -32,7 +33,7 @@ var config = {
3233
{
3334
selector: 'link[rel*="icon"]',
3435
attr: 'href'
35-
}
36+
},
3637
],
3738
subdirectories: [
3839
{

lib/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
var url = require('url');
22
var path = require('path');
33

4+
function isUrl(path) {
5+
var urlRegexp = /^((http[s]?:)?\/\/)/;
6+
return urlRegexp.test(path);
7+
}
8+
49
function getUrl(currentUrl, path) {
510
var pathObj = url.parse(path);
6-
if (!pathObj.protocol) {
11+
if (isUrl(path) && !pathObj.protocol) {
712
pathObj.protocol = 'http';
813
path = url.format(pathObj);
914
}
@@ -25,6 +30,7 @@ function getFilenameFromUrl (u) {
2530
}
2631

2732
module.exports = {
33+
isUrl: isUrl,
2834
getUrl: getUrl,
2935
getUnixPath: getUnixPath,
3036
getRelativePath: getRelativePath,

test/unit/utils-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ require('should');
22
var utils = require('../../lib/utils');
33

44
describe('Common utils', function () {
5+
describe('#isUrl(url)', function () {
6+
it('should return true if url starts with "http[s]://"', function () {
7+
utils.isUrl('http://google.com').should.be.true();
8+
utils.isUrl('https://github.com').should.be.true();
9+
});
10+
it('should return true if url starts with "//"', function () {
11+
utils.isUrl('//www.youtube.com').should.be.true();
12+
});
13+
it('should return false if url starts neither with "http[s]://" nor "//"', function () {
14+
utils.isUrl('http//www.youtube.com').should.be.false();
15+
utils.isUrl('http:/www.youtube.com').should.be.false();
16+
utils.isUrl('htt://www.youtube.com').should.be.false();
17+
utils.isUrl('://www.youtube.com').should.be.false();
18+
utils.isUrl('www.youtube.com').should.be.false();
19+
});
20+
});
21+
522
describe('#getUrl(url, path)', function () {
623
it('should return url + path if path is not url', function () {
724
utils.getUrl('http://google.com', '/path').should.be.equal('http://google.com/path');

0 commit comments

Comments
 (0)