2012-01-23 62 views
0

我用下面的節點模塊,因爲我想,以防止XSS: https://github.com/chriso/node-validator對象有沒有方法在節點驗證模塊更換

 str = str.replace(non_displayables[i], ''); 
       ^
TypeError: Object 0 has no method 'replace' 
    at remove_invisible_characters (C:\Users\Jack\Desktop\Dropbox\Nimble\node_mo 
dules\validator\lib\xss.js:180:19) 

我試圖清理以下信息並創建JSON對象:

var story = { 
    _id:   sanitize(data._id).xss(),   //string 
    title:  sanitize(data.title).xss(),  //string 
    deadline:  sanitize(data.deadline).xss(), //date string 
    description: sanitize(data.description).xss(), //string 
    sp:   sanitize(data.sp).xss(),   //number 
    value:  sanitize(data.value).xss(),  //number 
    roi:   sanitize(data.roi).xss(),   //decimal number 
    type:   sanitize(data.type).xss(),  //string 
    lane:   sanitize(data.lane).xss()   //Typically 0 
} 

我包括我的代碼頂部的模塊:sanitize = require('validator').sanitize;

線178 - 1從模塊xss.js的83:

function remove_invisible_characters(str) { 
    for (var i in non_displayables) { 
     str = str.replace(non_displayables[i], ''); 
    } 
    return str; 
} 
+4

你的問題是什麼? –

回答

3

從錯誤中,它看起來像你傳遞0(數字)到任何功能它是做這行str = str.replace(...);。數字沒有replace函數。如果該函數期望並要求其輸入是一個字符串,則可以確保通過使用str = String(str).replace(...);構造函數String在沒有new的情況下調用時進行類型轉換; details

相關問題