hexojs / hexo-server

Server module for Hexo.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: The header content contains invalid characters

thesadabc opened this issue · comments

commented

如果链接里包含urlencode 而且不以/结尾 会报错

比如 curl "http://localhost:4000/categories/web%E5%89%8D%E7%AB%AF" 会报下面这个错误

TypeError: The header content contains invalid characters
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:358:11)
    at /home/xjp/www/node_modules/hexo-server/lib/middlewares/route.js:27:11
    at call (/home/xjp/www/node_modules/connect/index.js:239:7)
    at next (/home/xjp/www/node_modules/connect/index.js:183:5)
    at /home/xjp/www/node_modules/hexo-server/lib/middlewares/header.js:9:5
    at call (/home/xjp/www/node_modules/connect/index.js:239:7)
    at next (/home/xjp/www/node_modules/connect/index.js:183:5)
    at call (/home/xjp/www/node_modules/connect/index.js:248:3)
    at next (/home/xjp/www/node_modules/connect/index.js:183:5)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at Function.handle (/home/xjp/www/node_modules/connect/index.js:186:3)

但是 curl "http://localhost:4000/categories/web%E5%89%8D%E7%AB%AF/" 就不会有问题

这个算是bug吗

bash$ hexo -v

hexo: 3.2.2
hexo-cli: 1.0.2
os: Darwin 16.3.0 darwin x64
http_parser: 2.7.0
node: 6.9.2
v8: 5.1.281.88
uv: 1.9.1
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 57.1
modules: 48
openssl: 1.0.2j
commented

查到问题了 lib/middlewares/route.js中的url解码后没有重新编码 导致302出错

  res.setHeader('Location', root + url + '/');

确实是个Bug,感谢PR。请修复下Travis的错误提示。

@NoahDragon npm 发个新版本吧,这个 bug 修复了,但是 npm 上没更新

@numbcoder 感谢提醒,马上更新

EDIT: 已更新。