Skip to content

Commit c5e477d

Browse files
committed
fix bug if publicPath starts with protocol
1 parent 4c5b819 commit c5e477d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const isDynamicSrc = (src) => /\{\{/.test(src);
1515

1616
const isStartsWithDot = (src) => /^\./.test(src);
1717

18+
const hasProcotol = (src) => /^(\w+:)?\/\//.test(src);
19+
1820
const replaceAt = (str, start, end, replacement) =>
1921
str.slice(0, start) + replacement + str.slice(end);
2022

@@ -121,7 +123,7 @@ export default function (content) {
121123
const module = await loadModule(request);
122124
let source = extract(module, publicPath);
123125
const isSourceAbsolute = isAbsolute(source);
124-
if (!isSourceAbsolute) {
126+
if (!isSourceAbsolute && !hasProcotol(source)) {
125127
source = ensureStartsWithDot(source);
126128
}
127129
if (enforceRelativePath && isSourceAbsolute) {

test/test.js

+8
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,12 @@ describe('wxml-loader', () => {
153153
await compile(code, { enforceRelativePath: true });
154154
expect(getCompiledRes()).toBe('<image src="./images/image.gif" />');
155155
});
156+
157+
test('should work if publicPath starts with protocol', async () => {
158+
const code = '<image src="./fixture.gif" />';
159+
await compile(code, { globalPublicPath: 'http://m.baidu.com/' });
160+
expect(getCompiledRes()).toBe(
161+
'<image src="http://m.baidu.com/fixture.gif" />',
162+
);
163+
});
156164
});

0 commit comments

Comments
 (0)