Sha256: d2b83d479045a54114a514ea3e7cb21226f3593e75267eb95c05eccd931f8d8b
Contents?: true
Size: 1.62 KB
Versions: 2
Compression:
Stored size: 1.62 KB
Contents
/* globals module, URL */ import { hasDOM } from 'ember-browser-environment'; import { IS_NODE, require } from 'node-module'; let nodeURL; let parsingNode; export default function installProtocolForURL(environment) { let protocol; if (hasDOM) { protocol = browserProtocolForURL.call(environment, 'foobar:baz'); } // Test to see if our DOM implementation parses // and normalizes URLs. if (protocol === 'foobar:') { // Swap in the method that doesn't do this test now that // we know it works. environment.protocolForURL = browserProtocolForURL; } else if (typeof URL === 'object') { // URL globally provided, likely from FastBoot's sandbox nodeURL = URL; environment.protocolForURL = nodeProtocolForURL; } else if (IS_NODE) { // Otherwise, we need to fall back to our own URL parsing. // Global `require` is shadowed by Ember's loader so we have to use the fully // qualified `module.require`. // tslint:disable-next-line:no-require-imports nodeURL = require('url'); environment.protocolForURL = nodeProtocolForURL; } else { throw new Error('Could not find valid URL parsing mechanism for URL Sanitization'); } } function browserProtocolForURL(url) { if (!parsingNode) { parsingNode = document.createElement('a'); } parsingNode.href = url; return parsingNode.protocol; } function nodeProtocolForURL(url) { let protocol = null; if (typeof url === 'string') { protocol = nodeURL.parse(url).protocol; } return protocol === null ? ':' : protocol; }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
discourse-ember-source-3.5.1.1 | dist/es/ember-glimmer/lib/protocol-for-url.js |
discourse-ember-source-3.5.1.0 | dist/dist/es/ember-glimmer/lib/protocol-for-url.js |