mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 10:33:22 +00:00
Fix #1165: correctly normalize path in summary to accept unicode
This commit is contained in:
@@ -39,6 +39,9 @@ function TOCArticle(def, parent) {
|
||||
var parts = this.ref.split('#');
|
||||
this.path = (parts.length > 1? parts.slice(0, -1).join('#') : this.ref);
|
||||
this.anchor = (parts.length > 1? '#' + _.last(parts) : null);
|
||||
|
||||
// Normalize path to remove ('./', etc)
|
||||
this.path = location.normalize(this.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ function isAnchor(href) {
|
||||
|
||||
// Normalize a path to be a link
|
||||
function normalize(s) {
|
||||
return s.replace(/\\/g, '/');
|
||||
return path.normalize(s).replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
// Convert relative to absolute path
|
||||
@@ -36,7 +36,7 @@ function normalize(s) {
|
||||
function toAbsolute(_href, dir, outdir) {
|
||||
if (isExternal(_href)) return _href;
|
||||
outdir = outdir == undefined? dir : outdir;
|
||||
|
||||
|
||||
_href = normalize(_href);
|
||||
dir = normalize(dir);
|
||||
outdir = normalize(outdir);
|
||||
|
||||
@@ -59,6 +59,34 @@ describe('Summary / Table of contents', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Unicode summary', function() {
|
||||
var book;
|
||||
|
||||
before(function() {
|
||||
return mockSummary({
|
||||
'SUMMARY.md': '# Summary\n\n'
|
||||
+ '* [Hello](./hello world.md)\n'
|
||||
+ '* [Spanish](./Descripción del problema.md)\n\n'
|
||||
+ '* [Chinese](读了这本书.md)\n\n'
|
||||
})
|
||||
.then(function(_book) {
|
||||
book = _book;
|
||||
});
|
||||
});
|
||||
|
||||
it('should accept article with spaces', function() {
|
||||
should(book.summary.getArticle('hello world.md')).be.ok();
|
||||
});
|
||||
|
||||
it('should accept article with chinese filename', function() {
|
||||
should(book.summary.getArticle('读了这本书.md')).be.ok();
|
||||
});
|
||||
|
||||
it('should accept article with accents', function() {
|
||||
should(book.summary.getArticle('Descripción del problema.md')).be.ok();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Non-empty summary list', function() {
|
||||
var book;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user