diff --git a/__tests__/utils.js b/__tests__/utils.js index 7e2884f..f617f31 100644 --- a/__tests__/utils.js +++ b/__tests__/utils.js @@ -265,6 +265,21 @@ test('.uriIsRelative() - "uri" is absolute - should return "false"', () => { ); }); +/** + * .uriIsSchemaLess() + */ + +test('.uriIsSchemaLess() - "uri" is schema less - should return "true"', () => { + expect(utils.uriIsSchemaLess('//localhost:700/manifest.json')).toBe(true); +}); + +test('.uriIsSchemaLess() - "uri" is not schema less - should return "false"', () => { + expect(utils.uriIsSchemaLess('http://localhost:7000/manifest.json')).toBe( + false, + ); +}); + + /** * .uriRelativeToAbsolute() */ diff --git a/lib/asset-css.js b/lib/asset-css.js index 4f64509..53086f0 100644 --- a/lib/asset-css.js +++ b/lib/asset-css.js @@ -1,7 +1,7 @@ 'use strict'; const { validate } = require('@podium/schemas'); -const { uriIsRelative, pathnameBuilder } = require('./utils'); +const { uriIsRelative, pathnameBuilder, uriIsSchemaLess } = require('./utils'); const { buildLinkElement, buildReactLinkAttributes } = require('./html-utils'); // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link @@ -93,7 +93,7 @@ const PodiumAssetCss = class PodiumAssetCss { get value() { const pathname = this[_prefix] ? this[_pathname] : ''; const value = this[_value]; - return uriIsRelative(value) ? pathnameBuilder(pathname, value) : value; + return uriIsRelative(value) && !uriIsSchemaLess(value) ? pathnameBuilder(pathname, value) : value; } set value(value) { diff --git a/lib/asset-js.js b/lib/asset-js.js index 2584f52..a35f95b 100644 --- a/lib/asset-js.js +++ b/lib/asset-js.js @@ -1,7 +1,7 @@ 'use strict'; const { validate } = require('@podium/schemas'); -const { uriIsRelative, pathnameBuilder } = require('./utils'); +const { uriIsRelative, pathnameBuilder, uriIsSchemaLess } = require('./utils'); const { buildScriptElement, buildReactScriptAttributes } = require('./html-utils'); // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script @@ -94,7 +94,7 @@ const PodiumAssetJs = class PodiumAssetJs { get value() { const pathname = this[_prefix] ? this[_pathname] : ''; const value = this[_value]; - return uriIsRelative(value) ? pathnameBuilder(pathname, value) : value; + return uriIsRelative(value) && !uriIsSchemaLess(value) ? pathnameBuilder(pathname, value) : value; } set value(value) { diff --git a/lib/utils.js b/lib/utils.js index 7f89e12..d53f385 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -100,6 +100,17 @@ const uriBuilder = (input = '', base = '', extra = '') => { const uriIsRelative = uri => uri.substr(0, 4) !== 'http'; + +/** + * Checks if a URI is schema less + * + * @param {String} uri A URI to check + * + * @returns {Boolean} + */ + +const uriIsSchemaLess = uri => uri.substr(0, 2) === '//'; + /** * Check if a URI is absolute or relative and if relative compose an * absolute URI out of a absolute mainfest URI. @@ -240,6 +251,7 @@ module.exports.isString = isString; module.exports.isFunction = isFunction; module.exports.uriBuilder = uriBuilder; module.exports.uriIsRelative = uriIsRelative; +module.exports.uriIsSchemaLess = uriIsSchemaLess; module.exports.pathnameBuilder = pathnameBuilder; module.exports.uriRelativeToAbsolute = uriRelativeToAbsolute; module.exports.setAtLocalsPodium = setAtLocalsPodium;