File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 11var 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 {
Original file line number Diff line number Diff line change 11var url = require ( 'url' ) ;
22var path = require ( 'path' ) ;
33
4+ function isUrl ( path ) {
5+ var urlRegexp = / ^ ( ( h t t p [ s ] ? : ) ? \/ \/ ) / ;
6+ return urlRegexp . test ( path ) ;
7+ }
8+
49function 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
2732module . exports = {
33+ isUrl : isUrl ,
2834 getUrl : getUrl ,
2935 getUnixPath : getUnixPath ,
3036 getRelativePath : getRelativePath ,
Original file line number Diff line number Diff line change @@ -2,6 +2,23 @@ require('should');
22var utils = require ( '../../lib/utils' ) ;
33
44describe ( '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' ) ;
You can’t perform that action at this time.
0 commit comments