NodeJS Express如何取消HTML实体的显示
我正在使用Express,Angular JS和Google App-Engine Datastore在NodeJS中构buildWeb应用程序。
我正在学习Node。 我创build了一个表单,在插入数据库之前“清理”(转义)用户input。 我遵循MDN网站上的NodeJS教程来创build这个代码:
//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文件path的列表。
所以当用户提交请求时,它以“Escaped”格式存储在数据库中。
//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
你可以试试这个:)
const querystring = require('querystring'); querystring.unescape(escape_str);
我能够使用“他”库来达到这个要求。
这里有一个post的细节: 什么是正确的方法来解码一个string,其中有特殊的HTML实体?
这是图书馆。 我能够使用npm install来安装它。
https://www.npmjs.com/package/he
示例解决scheme
const he = require('he'); let escape_str = '/top/example/test123.txt'; let unescaped_str = he.decode(escape_str); console.log('unescaped_str ' + unescaped_str);
- Node.js设置错误的内容长度。 我如何设置这一个
- 使用javascript / node.js在mongodb中查找带有另一个条件的对象的最早date
- 适用于Node.js的Google Docs API
- 同时访问两个远程资源并将其输出到合并的响应中 – NodeJS
- 为什么Node.js应用程序只能从127.0.0.1/localhost访问?
- 无法导入模块:您可能需要一个合适的加载程序
- 如何解决Gruntfile.js中错误configuration的grunt-connect-proxy设置的404错误?
- 简单的方法来增加任何更新查询的Mongoose文档版本?
- 在debugging控制台中探索承诺值