Skip to content

Commit bd25eeb

Browse files
committed
test(IDN): should encode root value
1 parent abd543e commit bd25eeb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

test/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict';
22

3-
const should = require('chai').should(); // eslint-disable-line
3+
require('chai').should();
44
const Hexo = require('hexo');
55
const nunjucks = require('nunjucks');
66
const env = new nunjucks.Environment();
77
const pathFn = require('path');
88
const fs = require('fs');
99
const cheerio = require('cheerio');
10+
const { encodeURL } = require('hexo-util');
1011

1112
env.addFilter('uriencode', str => {
1213
return encodeURI(str);
@@ -148,7 +149,6 @@ describe('Feed generator', () => {
148149
const $ = cheerio.load(result.data);
149150

150151
$('feed>id').text().should.eql(valid);
151-
$('feed>entry>link').attr('href').should.eql(valid);
152152
};
153153

154154
checkURL('http://localhost/', '/', 'http://localhost/');
@@ -170,20 +170,21 @@ describe('Feed generator', () => {
170170
path: 'atom.xml'
171171
};
172172

173-
const checkURL = function(url, root, valid) {
173+
const checkURL = function(url, root) {
174174
hexo.config.url = url;
175175
hexo.config.root = root;
176176

177177
const result = generator(locals);
178178
const $ = cheerio.load(result.data);
179179

180-
$('feed>id').text().should.eql(valid);
181-
$('feed>entry>link').attr('href').should.eql(valid);
180+
if (url[url.length - 1] !== '/') url += '/';
181+
const punyIDN = encodeURL(url);
182+
$('feed>id').text().should.eql(punyIDN);
182183
};
183-
const IDN = 'http://gôg.com/';
184-
checkURL(IDN, '/', IDN);
185184

186-
checkURL(IDN, 'blo g/', IDN);
185+
checkURL('http://gôg.com/', '/');
186+
187+
checkURL('http://gôg.com/bár', '/bár/');
187188
});
188189

189190
it('Root encoding', () => {

0 commit comments

Comments
 (0)