Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果md文件名中含有&等特殊字符,使用chrome浏览器等读取sitemap.xml会出现错误 #1

Closed
letiantian opened this issue May 16, 2014 · 6 comments

Comments

@letiantian
Copy link

sitemap.ejs中处理使用encodeURI函数处理了url:

<loc><%- encodeURI(post.permalink) %></loc>

如果创建文件/source/_posts/hello&world.md(文件名有点怪),能够正常访问http://127.0.0.1:4000/hello&world/,但是使用Firefox29,chrome30+访问/sitemap.xml会出现类似于下面的错误:

XML Parsing Error: not well-formed
Location: http://127.0.0.1:4000/sitemap.xml
Line Number 50, Column 47:    <loc>http://127.0.0.1:4000/hello&world/</loc>
----------------------------------------------^

encodeURI没有对&等字符进行处理,但是在静态博客中除了#其他的特殊字符可以不具有特殊意义。

我觉得可以再加些处理,例如

encodeURI(post.permalink).replace(/&/g,"%26").replace()....
@tommy351 tommy351 added the bug label May 16, 2014
@leesei
Copy link
Member

leesei commented Mar 7, 2016

@tommy351 I think Hexo was too lenient in generating links.
I think all links generated should be a URL safe characters.

This brings us back to the definition of permalink hexojs/hexo#881 (comment).

@curbengh
Copy link
Contributor

I think Hexo was too lenient in generating links.
I think all links generated should be a URL safe characters.

This brings us back to the definition of permalink hexojs/hexo#881 (comment).

One way to do it is to escape the permalink when generating it (except the domain part, which shall be punycoded).

const { format, parse } = require('url');
permalink = permalink.format({
        protocol: parse(permalink).protocol,
        hostname: parse(permalink).hostname,
        pathname: encodeURI(parse(permalink).pathname)
      });

This touches the same codebase as hexojs/hexo#3691

@curbengh
Copy link
Contributor

curbengh commented Jul 1, 2020

& is a reserved symbol for query string so it can't be encoded.

@curbengh curbengh closed this as completed Jul 1, 2020
@hsuchihting
Copy link

hsuchihting commented Sep 16, 2020

Hello~我想要部屬文章時跳出了這些錯誤,初步判斷應該是跟關鍵字有關與符號有關,但看了解決方法後,依然不知道怎麼改正,也將文章中有的特殊符號或關鍵字拿掉了,但依然無法成功部屬,請問在程式碼片端中出現特殊符號 (EX. @ or $ or / or | ...等)也會影響部屬嗎? 還請大家協助解答,謝謝。

Template render error: (unknown path)
  Error: filter not found: json
    at Object._prettifyError (F:\TimBlog\node_modules\nunjucks\src\lib.js:36:11)
    at F:\TimBlog\node_modules\nunjucks\src\environment.js:567:19
    at Template.root [as rootRenderFunc] (eval at _compile (F:\TimBlog\node_modules\nunjucks\src\environment.js:637:18), <anonymous>:19:3)
    at Template.render (F:\TimBlog\node_modules\nunjucks\src\environment.js:556:10)
    at Environment.renderString (F:\TimBlog\node_modules\nunjucks\src\environment.js:380:17)
    at F:\TimBlog\node_modules\hexo\lib\extend\tag.js:120:48
    at tryCatcher (F:\TimBlog\node_modules\bluebird\js\release\util.js:16:23)
    at Function.Promise.fromNode.Promise.fromCallback (F:\TimBlog\node_modules\bluebird\js\release\promise.js:209:30)
    at Tag.render (F:\TimBlog\node_modules\hexo\lib\extend\tag.js:120:18)
    at Object.onRenderEnd (F:\TimBlog\node_modules\hexo\lib\hexo\post.js:287:20)
    at F:\TimBlog\node_modules\hexo\lib\hexo\render.js:64:19
    at tryCatcher (F:\TimBlog\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (F:\TimBlog\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (F:\TimBlog\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (F:\TimBlog\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (F:\TimBlog\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (F:\TimBlog\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (F:\TimBlog\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (F:\TimBlog\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues (F:\TimBlog\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

@curbengh
Copy link
Contributor

Looks like a conflict with tag plugin syntax. Do you have {% json %} or {{ json }} in your post content?

@hsuchihting
Copy link

yes, I got the problem and solved it, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants