Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//
// At top level try cache first. On recursive calls skip cache.
// !! Cache should be probed even for disabled services, to resolve old links.
//
let result;
if (nestingLeft === this.nesting) {
result = await this.cache.get(url_normalized);
// If cache exists - use it.
if (result || result === null) {
// forward hash if needed
if (hash && result) {
u = mdurl.parse(result, true);
u.hash = u.hash || hash;
result = mdurl.format(u);
}
return result;
}
}
//
// First pass validation (quick).
//
if (!this._matchAllRE.test(url_normalized)) break;
// Something found - run additional checks.
let domainConfig = this._domains.find(dc => dc._compiledMatch.exec(url_normalized));
'.result-debug-content',
JSON.stringify(mdSrc.parse(source, { references: {} }), null, 2),
'json'
);
} else { /*defaults._view === 'html'*/
$('.result-html').html(mdHtml.render(source));
}
// reset lines mapping cache on content update
scrollMap = null;
try {
if (source) {
// serialize state - source and options
permalink.href = '#md3=' + mdurl.encode(JSON.stringify({
source: source,
defaults: _.omit(defaults, 'highlight')
}), '-_.!~', false);
} else {
permalink.href = '';
}
} catch (__) {
permalink.href = '';
}
}
let url_normalized = mdurl.format(u);
//
// At top level try cache first. On recursive calls skip cache.
// !! Cache should be probed even for disabled services, to resolve old links.
//
let result;
if (nestingLeft === this.nesting) {
result = await this.cache.get(url_normalized);
// If cache exists - use it.
if (result || result === null) {
// forward hash if needed
if (hash && result) {
u = mdurl.parse(result, true);
u.hash = u.hash || hash;
result = mdurl.format(u);
}
return result;
}
}
//
// First pass validation (quick).
//
if (!this._matchAllRE.test(url_normalized)) break;
// Something found - run additional checks.
if (parsed.hostname) {
// Encode hostnames in urls like:
// `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
//
// We don't encode unknown schemas, because it's likely that we encode
// something we shouldn't (e.g. `skype:name` treated as `skype:host`)
//
if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
try {
parsed.hostname = punycode.toASCII(parsed.hostname);
} catch (er) { /**/ }
}
}
return mdurl.encode(mdurl.format(parsed));
}
if (nestingLeft < 0) {
throw new UnshortError('Too many redirects', 'EBADREDIRECT');
}
let result = (url !== origUrl) ? url : null;
if (shouldCache) {
// Cache result.
// !! use normalized original URL for cache key.
let uo = mdurl.parse(origUrl, true);
uo.hash = '';
uo.protocol = uo.protocol || 'http';
await this.cache.set(mdurl.format(uo), result);
}
return result;
};
if (parsed.hostname) {
// Encode hostnames in urls like:
// `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
//
// We don't encode unknown schemas, because it's likely that we encode
// something we shouldn't (e.g. `skype:name` treated as `skype:host`)
//
if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
try {
parsed.hostname = punycode.toASCII(parsed.hostname);
} catch (er) { /**/ }
}
}
return mdurl.encode(mdurl.format(parsed));
}
if (parsed.hostname) {
// Encode hostnames in urls like:
// `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
//
// We don't encode unknown schemas, because it's likely that we encode
// something we shouldn't (e.g. `skype:name` treated as `skype:host`)
//
if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
try {
parsed.hostname = punycode.toASCII(parsed.hostname);
} catch (er) { /**/ }
}
}
return mdurl.encode(mdurl.format(parsed));
}
module.exports = normalizeLink;
if (!u.protocol) {
// set protocol for relative links like `//example.com`
u.protocol = 'http:';
}
// user-submitted url has weird protocol, just return `null` in this case
if (u.protocol !== 'http:' && u.protocol !== 'https:') break;
if (u.hash) {
// Copying browser-like behavior here: if we're not redirected to a hash,
// but original url has one, set it as a final hash.
hash = u.hash;
u.hash = '';
}
let url_normalized = mdurl.format(u);
//
// At top level try cache first. On recursive calls skip cache.
// !! Cache should be probed even for disabled services, to resolve old links.
//
let result;
if (nestingLeft === this.nesting) {
result = await this.cache.get(url_normalized);
// If cache exists - use it.
if (result || result === null) {
// forward hash if needed
if (hash && result) {
u = mdurl.parse(result, true);
u.hash = u.hash || hash;
if (parsed.hostname) {
// Encode hostnames in urls like:
// `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
//
// We don't encode unknown schemas, because it's likely that we encode
// something we shouldn't (e.g. `skype:name` treated as `skype:host`)
//
if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
try {
parsed.hostname = punycode.toUnicode(parsed.hostname);
} catch (er) { /**/ }
}
}
return mdurl.decode(mdurl.format(parsed));
}
// Encode hostnames in urls like:
// `http://host/`, `https://host/`, `mailto:user@host`, `//host/`
//
// We don't encode unknown schemas, because it's likely that we encode
// something we shouldn't (e.g. `skype:name` treated as `skype:host`)
//
if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) {
try {
parsed.hostname = punycode.toASCII(parsed.hostname);
} catch (er) {
/**/
}
}
}
return mdurl.encode(mdurl.format(parsed));
};