Skip to content

Commit

Permalink
test(IDN): should encode root value
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Sep 8, 2019
1 parent abd543e commit bd25eeb
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

const should = require('chai').should(); // eslint-disable-line
require('chai').should();
const Hexo = require('hexo');
const nunjucks = require('nunjucks');
const env = new nunjucks.Environment();
const pathFn = require('path');
const fs = require('fs');
const cheerio = require('cheerio');
const { encodeURL } = require('hexo-util');

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

$('feed>id').text().should.eql(valid);
$('feed>entry>link').attr('href').should.eql(valid);
};

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

const checkURL = function(url, root, valid) {
const checkURL = function(url, root) {
hexo.config.url = url;
hexo.config.root = root;

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

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

checkURL(IDN, 'blo g/', IDN);
checkURL('http://gôg.com/', '/');

checkURL('http://gôg.com/bár', '/bár/');
});

it('Root encoding', () => {
Expand Down

0 comments on commit bd25eeb

Please sign in to comment.