hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.46k stars 4.85k forks source link

Special symbols in post title cause errors #4122

Closed ProfessorX closed 4 years ago

ProfessorX commented 4 years ago

Check List

Please check followings before submitting a new feature request.

Feature Request

Others

Details of the issue and bug please refer to the issue that I posted on theme-next repo.

Portal here: https://github.com/theme-next/hexo-theme-next/issues/1370

OK for clarity I will use Chinese hereafter.

在Post md文件的标题中,如果用了 “%” 英文的百分比符号,会导致在hexo g的时候报错。

如:

---
layout: post
title:  "如果经济危机全面爆发,货币贬值99.9999% 那么我欠银行的100万房贷是还100万,还是100亿?"
date:   2019-11-24  19:00:00 +0800
categories: Report
tags: [World, Economy, Bank, Loan, Depreciation]
---

一个post抬头如上所示,保存后用hexo g进行编译,环境:

+-- hexo@4.2.0
+-- hexo-generator-archive@0.1.5
+-- hexo-generator-category@0.1.3
+-- hexo-generator-index@0.2.1
+-- hexo-generator-search@2.4.0
+-- hexo-generator-tag@0.2.0
+-- hexo-renderer-ejs@0.3.1
+-- hexo-renderer-marked@1.0.1
+-- hexo-renderer-stylus@0.3.3
`-- hexo-server@0.3.3

然后会报如下所示的错误:

TypeError: Cannot read property 'replace' of null
    at Hexo.externalLinkFilter (C:\Users\abrah\Documents\blog\node_modules\hexo\lib\plugins\filter\after_render\external_link.js:22:15)
    at Hexo.tryCatcher (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.<anonymous> (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\method.js:15:34)
    at C:\Users\abrah\Documents\blog\node_modules\hexo\lib\extend\filter.js:62:52
    at tryCatcher (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\util.js:16:23)
    at Object.gotValue (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\reduce.js:155:18)
    at Object.gotAccum (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\reduce.js:144:25)
    at Object.tryCatcher (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\promise.js:517:31)          at Promise._settlePromise (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\promise.js:574:18)
    at Promise._settlePromiseCtx (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\promise.js:611:10)
    at _drainQueueStep (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\async.js:142:12)
    at _drainQueue (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\async.js:131:9)
    at Async._drainQueues (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\abrah\Documents\blog\node_modules\bluebird\js\release\async.js:17:14)
    at processImmediate (internal/timers.js:439:21)

将百分比符号去掉或者修改为中文“百分比”即可正常编译。因为我不懂js,所以没办法手工修改加 pull request.

以上,此致敬礼。

ProfessorX commented 4 years ago

Update: This works OK with hexo 4.0.0 and theme-next 7.5.0 or below.

ProfessorX commented 4 years ago

灵夫: 感觉上是

灵夫: 你对一个null变量调用了replace方法

灵夫: 要不提前判断下,传入字符串变量问题


@SukkaW
Please help refactor this js file, again. Many thanks.

stevenjoezhang commented 4 years ago

虽然报错来自 external_links.js ,但这个问题实际上与 external_links.js 无关。 这个 Issue 先关了。对于标题中的百分号等特殊符号的处理,请加入这里的讨论: https://github.com/hexojs/hexo/issues/4104