Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('url - IDN', () => {
const ctx = {
page: {},
config: hexo.config,
is_post: isPost,
url: 'https://foô.com/bár'
};
const result = openGraph.call(ctx);
result.should.contain(meta({property: 'og:url', content: encodeURL(ctx.url)}));
});
const checkURL = function(url, root) {
hexo.config.url = url;
hexo.config.root = root;
const feedCfg = hexo.config.feed;
const result = generator(locals, feedCfg.type, feedCfg.path);
const $ = cheerio.load(result.data);
if (url[url.length - 1] !== '/') url += '/';
const punyIDN = encodeURL(url);
$('feed>id').text().should.eql(punyIDN);
};
const urlA = '/foo/bár.jpg';
const urlB = 'http://fóo.com/bar.jpg';
const body = [
`![](${urlA})`,
`![](${urlB})`
].join('\n');
const r = require('../lib/renderer').bind(hexo);
const result = await r({text: body});
result.should.eql([
`<p><img data-src="${encodeURL(urlA)}">`,
`<img data-src="${encodeURL(urlB)}"></p>\n`
].join('\n'));
});
});
const zh = '这是-H1-标题';
const zhs = zh.replace(/-/g, ' ');
const de = 'Ich-♥-Deutsch';
const des = de.replace(/-/g, ' ');
const ru = 'Я-люблю-русский';
const rus = ru.replace(/-/g, ' ');
const input = [
`<h1 id="${zh}">${zhs}</h1>`,
`<h1 id="${de}">${des}</h1>`,
`<h1 id="${ru}">${rus}</h1>`
].join('');
const expected = [
`<ol class="${className}">`,
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(zh)}" class="${className}-link"><span class="${className}-text">${zhs}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(de)}" class="${className}-link"><span class="${className}-text">${des}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(ru)}" class="${className}-link"><span class="${className}-text">${rus}</span></a>`,
'</li></ol>'
].join('');
toc(input, { list_number: false, class: className }).should.eql(expected);
});
const des = de.replace(/-/g, ' ');
const ru = 'Я-люблю-русский';
const rus = ru.replace(/-/g, ' ');
const input = [
`<h1 id="${zh}">${zhs}</h1>`,
`<h1 id="${de}">${des}</h1>`,
`<h1 id="${ru}">${rus}</h1>`
].join('');
const expected = [
`<ol class="${className}">`,
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(zh)}" class="${className}-link"><span class="${className}-text">${zhs}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(de)}" class="${className}-link"><span class="${className}-text">${des}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(ru)}" class="${className}-link"><span class="${className}-text">${rus}</span></a>`,
'</li></ol>'
].join('');
toc(input, { list_number: false, class: className }).should.eql(expected);
});
const input = [
`<h1 id="${zh}">${zhs}</h1>`,
`<h1 id="${de}">${des}</h1>`,
`<h1 id="${ru}">${rus}</h1>`
].join('');
const expected = [
`<ol class="${className}">`,
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(zh)}" class="${className}-link"><span class="${className}-text">${zhs}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(de)}" class="${className}-link"><span class="${className}-text">${des}</span></a>`,
'</li>',
`<li class="${className}-item ${className}-level-1">`,
`<a href="#${encodeURL(ru)}" class="${className}-link"><span class="${className}-text">${rus}</span></a>`,
'</li></ol>'
].join('');
toc(input, { list_number: false, class: className }).should.eql(expected);
});
}
let result = '';
if (description) {
result += meta('description', description);
}
result += og('og:type', type);
result += og('og:title', title);
if (url) {
if (config.pretty_urls.trailing_index === false) {
url = url.replace(/index\.html$/, '');
}
url = encodeURL(url);
}
result += og('og:url', url);
result += og('og:site_name', siteName);
if (description) {
result += og('og:description', description);
}
if (language) {
if (language.length === 2) {
language = language.replace(localeRegex, str => localeMap[str]);
result += og('og:locale', language);
} else if (language.length === 5) {
const territory = language.slice(-2);
const territoryRegex = new RegExp(territory.concat('$'));
images,
keywords,
twitterId
} = this.props;
const htmlTags = [];
if (description) {
description = escapeHTML(stripHTML(description).substring(0, 200).trim())
.replace(/\n/g, ' ');
htmlTags.push();
}
htmlTags.push();
htmlTags.push();
htmlTags.push();
htmlTags.push();
if (description) {
htmlTags.push();
}
if (language) {
if (language.length === 2) {
language = language.replace(localeRegex, str => localeMap[str]);
htmlTags.push();
} else if (language.length === 5) {
const territory = language.slice(-2);
const territoryRegex = new RegExp(territory.concat('$'));
language = language.replace('-', '_').replace(territoryRegex, territory.toUpperCase());
htmlTags.push();
}