Skip to content

Commit f662ec8

Browse files
committed
Merge branch 'ln-e-remote-url-patch'
2 parents e6f313c + 0574b53 commit f662ec8

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ var postcss = require('postcss');
1818
*/
1919

2020
function isRemotePath(filePath) {
21-
return /^https?:\/\//.test(filePath);
21+
return /^(?:https?:)?\/\//.test(filePath);
22+
}
23+
24+
function normalizeUrl(url) {
25+
return /^\/\//.test(url) ? 'http:' + url : url;
2226
}
2327

2428
/**
@@ -29,7 +33,7 @@ function isRemotePath(filePath) {
2933
*/
3034

3135
function isAbsolutePath(filePath) {
32-
return filePath.indexOf('/') === 0;
36+
return /^\/(?!\/)/.test(filePath);
3337
}
3438

3539
/**
@@ -119,7 +123,7 @@ function getResourcePath(str, relativePath, absolutePath) {
119123
function getRemoteFileHash(file) {
120124
return new Promise(function (resolve, reject) {
121125
var client = /^https/.test(file) ? https : http;
122-
client.get(file, function (res) {
126+
client.get(normalizeUrl(file), function (res) {
123127
var md5 = crypto.createHash('md5');
124128

125129
res.on('data', function (chunk) {
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
body {
22
background: url(http://127.0.0.1:10010/images/test.png?v=e19ac7dee6);
3-
}
3+
}
4+
5+
body {
6+
background: url(//127.0.0.1:10010/images/test.png?v=e19ac7dee6);
7+
}

test/fixtures/test-remote.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
body {
22
background: url(http://127.0.0.1:10010/images/test.png);
3-
}
3+
}
4+
5+
body {
6+
background: url(//127.0.0.1:10010/images/test.png);
7+
}

0 commit comments

Comments
 (0)