我将在NodeJS、Express、Angular JS和Google应用引擎数据存储中构建Web应用程序。
我正在学习Node。 我创建了一个表单,在将用户输入插入数据库之前“净化”(转义)它。 我遵循MDN网站上NodeJS教程创建了这段代码:
“requested_filepath_list”是一个UNIX文件路径列表。
当用户提交请求时,它以“转义”的格式存储在数据库中。
我尝试了unescape函数,但似乎不起作用,它只是返回相同的输出。
我正在学习Node。 我创建了一个表单,在将用户输入插入数据库之前“净化”(转义)它。 我遵循MDN网站上NodeJS教程创建了这段代码:
//Trim and escape all inputs
req.sanitize('requester').escape();
req.sanitize('requester').trim();
req.sanitize('dataowner').escape();
req.sanitize('dataowner').trim();
req.sanitize('requested_filepath_list').escape();
req.sanitize('requested_filepath_list').trim();
“requested_filepath_list”是一个UNIX文件路径列表。
当用户提交请求时,它以“转义”的格式存储在数据库中。
//Escaped data
/top/example/test123.txt
问题: 如何“取消转义”数据以便进行显示?
//Desired output
/top/example/test123.txt
我尝试了unescape函数,但似乎不起作用,它只是返回相同的输出。
let escape_str = '/top/example/test123.txt';
let unescaped_str = unescape(escape_str);
console.log('unescaped_str: ' + unescaped_str);
//Output
unescaped_str: /top/example/test123.txt
//Desired output
/top/example/test123.txt