13

博客折腾记:hexo-leancloud-counter-security 与标题中的引号冲突

 3 years ago
source link: https://xiang578.com/post/meet-leancloud-counter-security-problem.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

博客折腾记:hexo-leancloud-counter-security 与标题中的引号冲突

发表于

2019-05-25 更新于 2021-04-12 分类于 站务

阅读次数: 574 本文字数: 660

昨天按照 hexo-theme-next/LEANCLOUD-COUNTER-SECURITY.md at master · theme-next/hexo-theme-next 这个文档配置博客阅读次数时,遇到 hexo-leancloud-counter-security 插件的一个冲突。

完成配置使用 hexo -d 时,终端中出现下面的错误提示:

 ATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
SyntaxError: Unexpected token h in JSON at position 30
at JSON.parse (<anonymous>)
at /Users/didi/Documents/personal/xiang578.github.io/node_modules/hexo-leancloud-counter-security/index.js:92:42
at arrayEach (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@lodash/lodash.js:516:11)
at Function.forEach (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@lodash/lodash.js:9344:14)
at Hexo._callee$ (/Users/didi/Documents/personal/xiang578.github.io/node_modules/hexo-leancloud-counter-security/index.js:83:27)
at tryCatch (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@regenerator-runtime/runtime.js:114:21)
at step (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@babel-runtime/helpers/asyncToGenerator.js:17:30)
at /Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@babel-runtime/helpers/asyncToGenerator.js:28:13
at process._tickCallback (internal/process/next_tick.js:68:7)

看提示貌似是利用 Json 解析字符串的时候出现问题。打开 node_modules/hexo-leancloud-counter-security/index.js:92,对应出现一个解析 JSON的:

y = JSON.parse(memoData[memoIdx].substring(0, memoData[memoIdx].length - 1));

js 没有怎么接触过,不知道能不能单步调试之类的,只好祭出输出调试大法,加上两个输出:

console.log(memoIdx)
console.log(memoData[memoIdx])
y = JSON.parse(memoData[memoIdx].substring(0,memoData[memoIdx].length - 1));

然后再执行 hexo -d 命令,命令行输出为:

28
{"title":"System.out.println("hello world!");","url":"/post/hello-world.html"},
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
SyntaxError: Unexpected token h in JSON at position 30
at JSON.parse (<anonymous>)
at /Users/didi/Documents/personal/xiang578.github.io/node_modules/hexo-leancloud-counter-security/index.js:92:42
at arrayEach (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@lodash/lodash.js:516:11)
at Function.forEach (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@lodash/lodash.js:9344:14)
at Hexo._callee$ (/Users/didi/Documents/personal/xiang578.github.io/node_modules/hexo-leancloud-counter-security/index.js:83:27)
at tryCatch (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as next] (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@regenerator-runtime/runtime.js:114:21)
at step (/Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@babel-runtime/helpers/asyncToGenerator.js:17:30)
at /Users/didi/Documents/personal/xiang578.github.io/node_modules/[email protected]@babel-runtime/helpers/asyncToGenerator.js:28:13
at process._tickCallback (internal/process/next_tick.js:68:7)

JSON 在解析字符串{"title":"System.out.println("hello world!");","url":"/post/hello-world.html"} 时出现错误。对应的正是之前写的一篇名为 System.out.println("hello world!"); 的文章,由于 JSON 格式中字符串是需要用"" 修饰,导致JSON 中出现了一个 "title":"System.out.println("hello world!");" key-value 组合。然而实际上 JSON 只会将 "System.out.println("h 解析成 value,之后出现的 h 被当成非法字符报错。

定位问题之后,暂时修改文章的标题为 hello world! | 算法花园,绕过部署失败。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK