From 0a3d41d3f8b2ea6eb23518e003bf3140e63cd19e Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Sun, 8 Sep 2019 07:17:01 +0100 Subject: [PATCH] test(idn): should encode url except domain --- test/index.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/index.js b/test/index.js index 316788f..93fc288 100644 --- a/test/index.js +++ b/test/index.js @@ -3,6 +3,7 @@ require('chai').should(); const Hexo = require('hexo'); const cheerio = require('cheerio'); +const { encodeURL } = require('hexo-util'); describe('Sitemap generator', () => { const hexo = new Hexo(__dirname, {silent: true}); @@ -68,3 +69,38 @@ describe('Sitemap generator', () => { }); }); }); + +describe('IDN', () => { + const hexo = new Hexo(__dirname, {silent: true}); + hexo.config.sitemap = { + path: 'sitemap.xml' + }; + const Post = hexo.model('Post'); + const generator = require('../lib/generator').bind(hexo); + let locals = {}; + + before(() => { + return hexo.init().then(() => { + return Post.insert([ + {source: 'foo', slug: 'foo', updated: 1e8}, + {source: 'bar', slug: 'bar', updated: 1e8 + 1}, + {source: 'baz', slug: 'baz', updated: 1e8 - 1} + ]).then(data => { + locals = hexo.locals.toObject(); + }); + }); + }); + + it('Default', () => { + hexo.config.url = 'http://fôo.com/bár'; + const parsedUrl = encodeURL(hexo.config.url); + + const result = generator(locals); + const $ = cheerio.load(result.data); + + $('url').each((index, element) => { + $(element).children('loc').text().startsWith(parsedUrl).should.be.true; + }); + hexo.config.url = 'http://yoursite.com/'; + }); +});