在我的nodejs應用程序中篩選所有輸入數據,我使用express-validator。事情是這樣的:快速驗證器拋出異常
app.post('/', function (req, res) {
req.sanitize('login').xss();
req.sanitize('password').xss();
//etc.
});
所以我的觀點是:
form(action='/', method='POST')
input(name='login', type='text')
input(name='password', type='password')
input(type='submit')
所有工作正常,但如果我忽略登錄字段,例如:
form(action='/', method='POST')
input(name='login', type='text')
input(name='password', type='password')
input(type='submit')
然後我得到異常。爲什麼不存在express-validator check param?
我也有過這個問題,但是我把所有東西都包裝進了try {} catch {}。真的很醜但:: – alessioalex 2012-01-11 13:36:23
謝謝你的迴應。我有這個問題。假設用戶輸入無效的登錄名,並且我需要在視圖中顯示適當的消息。你能提供一小塊代碼來處理這種情況嗎? – Erik 2012-01-11 16:12:50
無效登錄是什麼意思? – alessioalex 2012-01-11 16:27:48