diff --git a/src/runtime/getUrl.js b/src/runtime/getUrl.js index c2e3d506..1ae687a3 100644 --- a/src/runtime/getUrl.js +++ b/src/runtime/getUrl.js @@ -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; diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 40572090..fcc81263 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/test/runtime/__snapshots__/getUrl.test.js.snap b/test/runtime/__snapshots__/getUrl.test.js.snap index d3f84ed3..58b3bb21 100644 --- a/test/runtime/__snapshots__/getUrl.test.js.snap +++ b/test/runtime/__snapshots__/getUrl.test.js.snap @@ -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\\""`; @@ -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\\""`; diff --git a/test/runtime/getUrl.test.js b/test/runtime/getUrl.test.js index aecf8d26..14ca22ab 100644 --- a/test/runtime/getUrl.test.js +++ b/test/runtime/getUrl.test.js @@ -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();