原以为 encodeURIComponent()
是一个安全的不会抛异常的方法,但是最近日志里面捕获到一个 URIError,来自querystring.js
google了一下,从这段代码的实现,可以复现此异常:
> encodeURIComponent(String.fromCharCode(0xDFFF))
URIError: URI malformed
at repl:1:2
at REPLServer.eval (repl.js:80:21)
at Interface.<anonymous> (repl.js:182:12)
at Interface.emit (events.js:67:17)
at Interface._onLine (readline.js:162:10)
at Interface._line (readline.js:426:8)
at Interface._ttyWrite (readline.js:603:14)
at ReadStream.<anonymous> (readline.js:82:12)
at ReadStream.emit (events.js:88:20)
at ReadStream._emitKey (tty.js:327:10)
现在还没解决的疑问,是这种数据是如何传递过去的。
4 回复
昨天无意间捕捉到了这个错误:
URIError: URI malformed
at f:\nodeclub\nodeclub\node_modules\express\node_modules\connect\lib\middleware\static.js:119:14
at Object.static [as handle] (f:\nodeclub\nodeclub\node_modules\express\node_modules\connect\lib\middleware\static.j
s:60:5)
at next (f:\nodeclub\nodeclub\node_modules\express\node_modules\connect\lib\http.js:204:15)
at f:\nodeclub\nodeclub\node_modules\express\node_modules\connect\lib\middleware\csrf.js:80:37
at Object.handle (f:\nodeclub\nodeclub\app.js:39:5)
at next (f:\nodeclub\nodeclub\node_modules\express\node_modules\connect\lib\http.js:204:15)
at f:\nodeclub\nodeclub\controllers\sign.js:280:14
at f:\nodeclub\nodeclub\controllers\message.js:215:12
at f:\nodeclub\nodeclub\node_modules\mongoose\lib\utils.js:408:16
at [object Object].<anonymous> (f:\nodeclub\nodeclub\node_modules\mongoose\node_modules\mongodb\lib\mongodb\collecti
on.js:531:7)
不知道怎么出来的,后来再试,无法复现