Skip to content

Commit

Permalink
fix: do not crash when an assert return null or undefined (#1006)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Dec 6, 2019
1 parent 80e9662 commit 6769783
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/runtime/getUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (url, options) => {
}

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

if (typeof url !== 'string') {
return url;
Expand Down
12 changes: 6 additions & 6 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ exports[`loader should compile with \`css\` entry point (with \`modules\` and sc
}
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
url = url.__esModule ? url.default : url;
url = url && url.__esModule ? url.default : url;
if (typeof url !== 'string') {
return url;
Expand Down Expand Up @@ -414,7 +414,7 @@ exports[`loader should compile with \`css\` entry point (with \`modules\` and sc
}
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
url = url.__esModule ? url.default : url;
url = url && url.__esModule ? url.default : url;
if (typeof url !== 'string') {
return url;
Expand Down Expand Up @@ -743,7 +743,7 @@ exports[`loader should compile with \`css\` entry point: escape 1`] = `
}
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
url = url.__esModule ? url.default : url;
url = url && url.__esModule ? url.default : url;
if (typeof url !== 'string') {
return url;
Expand Down Expand Up @@ -1048,7 +1048,7 @@ exports[`loader should compile with \`js\` entry point: escape 1`] = `
}
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
url = url.__esModule ? url.default : url;
url = url && url.__esModule ? url.default : url;
if (typeof url !== 'string') {
return url;
Expand Down Expand Up @@ -1547,7 +1547,7 @@ module.exports = (url, options) => {
}
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
url = url.__esModule ? url.default : url;
url = url && url.__esModule ? url.default : url;
if (typeof url !== 'string') {
return url;
Expand Down Expand Up @@ -1824,7 +1824,7 @@ module.exports = (url, options) => {
}
// eslint-disable-next-line no-underscore-dangle, no-param-reassign
url = url.__esModule ? url.default : url;
url = url && url.__esModule ? url.default : url;
if (typeof url !== 'string') {
return url;
Expand Down
54 changes: 29 additions & 25 deletions test/runtime/__snapshots__/getUrl.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,73 @@

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

exports[`escape should escape url 2`] = `"image.png"`;
exports[`escape should escape url 2`] = `null`;

exports[`escape should escape url 3`] = `"image.png"`;
exports[`escape should escape url 3`] = `undefined`;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

exports[`escape should escape url 43`] = `"\\"image other.png#hash\\""`;
3 changes: 3 additions & 0 deletions test/runtime/getUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const getUrl = require('../../src/runtime/getUrl');
describe('escape', () => {
it('should escape url', () => {
expect(getUrl(true)).toMatchSnapshot();
expect(getUrl(null)).toMatchSnapshot();
// eslint-disable-next-line no-undefined
expect(getUrl(undefined)).toMatchSnapshot();
expect(getUrl('image.png')).toMatchSnapshot();
expect(getUrl('"image.png"')).toMatchSnapshot();
expect(getUrl("'image.png'")).toMatchSnapshot();
Expand Down

0 comments on commit 6769783

Please sign in to comment.