Skip to content

Commit 6769783

Browse files
authoredDec 6, 2019
fix: do not crash when an assert return null or undefined (#1006)
1 parent 80e9662 commit 6769783

File tree

4 files changed

+39
-32
lines changed

4 files changed

+39
-32
lines changed
 

‎src/runtime/getUrl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = (url, options) => {
55
}
66

77
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
8-
url = url.__esModule ? url.default : url;
8+
url = url && url.__esModule ? url.default : url;
99

1010
if (typeof url !== 'string') {
1111
return url;

‎test/__snapshots__/loader.test.js.snap

+6-6
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ exports[`loader should compile with \`css\` entry point (with \`modules\` and sc
109109
}
110110
111111
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
112-
url = url.__esModule ? url.default : url;
112+
url = url && url.__esModule ? url.default : url;
113113
114114
if (typeof url !== 'string') {
115115
return url;
@@ -414,7 +414,7 @@ exports[`loader should compile with \`css\` entry point (with \`modules\` and sc
414414
}
415415
416416
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
417-
url = url.__esModule ? url.default : url;
417+
url = url && url.__esModule ? url.default : url;
418418
419419
if (typeof url !== 'string') {
420420
return url;
@@ -743,7 +743,7 @@ exports[`loader should compile with \`css\` entry point: escape 1`] = `
743743
}
744744
745745
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
746-
url = url.__esModule ? url.default : url;
746+
url = url && url.__esModule ? url.default : url;
747747
748748
if (typeof url !== 'string') {
749749
return url;
@@ -1048,7 +1048,7 @@ exports[`loader should compile with \`js\` entry point: escape 1`] = `
10481048
}
10491049
10501050
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
1051-
url = url.__esModule ? url.default : url;
1051+
url = url && url.__esModule ? url.default : url;
10521052
10531053
if (typeof url !== 'string') {
10541054
return url;
@@ -1547,7 +1547,7 @@ module.exports = (url, options) => {
15471547
}
15481548
15491549
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
1550-
url = url.__esModule ? url.default : url;
1550+
url = url && url.__esModule ? url.default : url;
15511551
15521552
if (typeof url !== 'string') {
15531553
return url;
@@ -1824,7 +1824,7 @@ module.exports = (url, options) => {
18241824
}
18251825
18261826
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
1827-
url = url.__esModule ? url.default : url;
1827+
url = url && url.__esModule ? url.default : url;
18281828
18291829
if (typeof url !== 'string') {
18301830
return url;

‎test/runtime/__snapshots__/getUrl.test.js.snap

+29-25
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,73 @@
22

33
exports[`escape should escape url 1`] = `true`;
44

5-
exports[`escape should escape url 2`] = `"image.png"`;
5+
exports[`escape should escape url 2`] = `null`;
66

7-
exports[`escape should escape url 3`] = `"image.png"`;
7+
exports[`escape should escape url 3`] = `undefined`;
88

99
exports[`escape should escape url 4`] = `"image.png"`;
1010

11-
exports[`escape should escape url 5`] = `"\\"image other.png\\""`;
11+
exports[`escape should escape url 5`] = `"image.png"`;
1212

13-
exports[`escape should escape url 6`] = `"\\"image other.png\\""`;
13+
exports[`escape should escape url 6`] = `"image.png"`;
1414

1515
exports[`escape should escape url 7`] = `"\\"image other.png\\""`;
1616

17-
exports[`escape should escape url 8`] = `"\\"image\\\\\\"other.png\\""`;
17+
exports[`escape should escape url 8`] = `"\\"image other.png\\""`;
1818

19-
exports[`escape should escape url 9`] = `"\\"image\\\\nother.png\\""`;
19+
exports[`escape should escape url 9`] = `"\\"image other.png\\""`;
2020

21-
exports[`escape should escape url 10`] = `"image.png#hash"`;
21+
exports[`escape should escape url 10`] = `"\\"image\\\\\\"other.png\\""`;
2222

23-
exports[`escape should escape url 11`] = `"image.png#hash"`;
23+
exports[`escape should escape url 11`] = `"\\"image\\\\nother.png\\""`;
2424

2525
exports[`escape should escape url 12`] = `"image.png#hash"`;
2626

27-
exports[`escape should escape url 13`] = `"\\"image other.png#hash\\""`;
27+
exports[`escape should escape url 13`] = `"image.png#hash"`;
2828

29-
exports[`escape should escape url 14`] = `"\\"image other.png#hash\\""`;
29+
exports[`escape should escape url 14`] = `"image.png#hash"`;
3030

3131
exports[`escape should escape url 15`] = `"\\"image other.png#hash\\""`;
3232

33-
exports[`escape should escape url 16`] = `"\\"image other.png\\""`;
33+
exports[`escape should escape url 16`] = `"\\"image other.png#hash\\""`;
3434

35-
exports[`escape should escape url 17`] = `"\\"image other.png\\""`;
35+
exports[`escape should escape url 17`] = `"\\"image other.png#hash\\""`;
3636

3737
exports[`escape should escape url 18`] = `"\\"image other.png\\""`;
3838

39-
exports[`escape should escape url 19`] = `"image.png"`;
39+
exports[`escape should escape url 19`] = `"\\"image other.png\\""`;
4040

41-
exports[`escape should escape url 20`] = `"image.png"`;
41+
exports[`escape should escape url 20`] = `"\\"image other.png\\""`;
4242

4343
exports[`escape should escape url 21`] = `"image.png"`;
4444

45-
exports[`escape should escape url 22`] = `"\\"image other.png\\""`;
45+
exports[`escape should escape url 22`] = `"image.png"`;
4646

47-
exports[`escape should escape url 23`] = `"\\"image other.png\\""`;
47+
exports[`escape should escape url 23`] = `"image.png"`;
4848

4949
exports[`escape should escape url 24`] = `"\\"image other.png\\""`;
5050

51-
exports[`escape should escape url 25`] = `"\\"image\\\\\\"other.png\\""`;
51+
exports[`escape should escape url 25`] = `"\\"image other.png\\""`;
5252

53-
exports[`escape should escape url 26`] = `"\\"image\\\\nother.png\\""`;
53+
exports[`escape should escape url 26`] = `"\\"image other.png\\""`;
5454

55-
exports[`escape should escape url 27`] = `"image.png#hash"`;
55+
exports[`escape should escape url 27`] = `"\\"image\\\\\\"other.png\\""`;
5656

57-
exports[`escape should escape url 28`] = `"image.png#hash"`;
57+
exports[`escape should escape url 28`] = `"\\"image\\\\nother.png\\""`;
5858

5959
exports[`escape should escape url 29`] = `"image.png#hash"`;
6060

61-
exports[`escape should escape url 30`] = `"\\"image other.png#hash\\""`;
61+
exports[`escape should escape url 30`] = `"image.png#hash"`;
6262

63-
exports[`escape should escape url 31`] = `"\\"image other.png\\""`;
63+
exports[`escape should escape url 31`] = `"image.png#hash"`;
6464

65-
exports[`escape should escape url 32`] = `"\\"image other.png\\""`;
65+
exports[`escape should escape url 32`] = `"\\"image other.png#hash\\""`;
6666

6767
exports[`escape should escape url 33`] = `"\\"image other.png\\""`;
6868

69-
exports[`escape should escape url 34`] = `"\\"image other.png#hash\\""`;
69+
exports[`escape should escape url 34`] = `"\\"image other.png\\""`;
7070

71-
exports[`escape should escape url 35`] = `"\\"image other.png#hash\\""`;
71+
exports[`escape should escape url 35`] = `"\\"image other.png\\""`;
7272

7373
exports[`escape should escape url 36`] = `"\\"image other.png#hash\\""`;
7474

@@ -81,3 +81,7 @@ exports[`escape should escape url 39`] = `"\\"image other.png#hash\\""`;
8181
exports[`escape should escape url 40`] = `"\\"image other.png#hash\\""`;
8282

8383
exports[`escape should escape url 41`] = `"\\"image other.png#hash\\""`;
84+
85+
exports[`escape should escape url 42`] = `"\\"image other.png#hash\\""`;
86+
87+
exports[`escape should escape url 43`] = `"\\"image other.png#hash\\""`;

‎test/runtime/getUrl.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const getUrl = require('../../src/runtime/getUrl');
33
describe('escape', () => {
44
it('should escape url', () => {
55
expect(getUrl(true)).toMatchSnapshot();
6+
expect(getUrl(null)).toMatchSnapshot();
7+
// eslint-disable-next-line no-undefined
8+
expect(getUrl(undefined)).toMatchSnapshot();
69
expect(getUrl('image.png')).toMatchSnapshot();
710
expect(getUrl('"image.png"')).toMatchSnapshot();
811
expect(getUrl("'image.png'")).toMatchSnapshot();

0 commit comments

Comments
 (0)
Please sign in to comment.