简体   繁体   English

无法使用javascript使用_查询Postgres数据库

[英]Unable to query postgres db with _ using javascript

I'm trouble shooting this application that I ave had no hand in creating, but I get to fix. 我在拍摄我没有创建过的这个应用程序时遇到了麻烦,但是我可以解决。 Anywho, I'm finding that I am unable to query the postgres db for any variable that has an _. 任何人,我发现我无法查询postgres db中具有_的任何变量。 Now before you say use escape characters, I've already been there, done that, and got the t-shirt. 现在,在您说使用转义字符之前,我已经去过那里,做到了,得到了T恤。 From what I could tell, the application uses escape-string-regexp module to alter the string, for example => "some_random@email.com" => "some_random@email\\.com" I added my own module to single out the _ and now the output is => "some\\\\_random@email\\.com". 据我所知,该应用程序使用escape-string-regexp模块来更改字符串,例如=>“ some_random@email.com” =>“ some_random @ email \\ .com”我添加了自己的模块以选择_,现在输出为=>“ some \\\\ _ random @ email \\ .com”。 Note the two escapes for the underscore as prescribed by the mass forums that I have scaled. 请注意,按我已扩展的群众论坛的规定,底线有两个转义符。 I even built a tool to test out in python and that works. 我什至建立了一个可以在python中进行测试的工具,并且可以正常工作。 Slightly different as I use => "(E'some\\\\_random@email\\\\.com')". 与我使用=>“((E'some \\\\ _ random @ email \\\\。com')”)稍有不同。 Tried that with javascript as well and still no dice. 也尝试过使用javascript,但仍然没有骰子。 What say all ye? 怎么说呢? Oh, this shoots out via expressjs from what I can tell. 哦,据我所知,这是通过expressjs发出的。 I'm not a javascript guy. 我不是javascript人。

Found the solution. 找到了解决方案。 I and another team mate went back and revisited the method I created and changed the " to '. Next thing you know, it started working. 我和另一个队友返回并重新访问了我创建的方法,并将“”更改为“。”接下来,您知道了它开始起作用。

exports.stringChanger = function(word){
//console.log(word)
var metas = ["_"];
var guestPool = word.split("");

//console.log(guestPool)

for(i in range(guestPool.length)){
    for(j in range(metas.length)){
        if(guestPool[i] === metas[j]){
            guestPool[i] = "\\" + guestPool[i];
        }
    }
}

var guest = guestPool.join("");
return guest;
//console.log(guest)

}; };

to

exports.stringChanger = function(word){
//console.log(word)
var metas = ['_'];
var guestPool = word.split("");

//console.log(guestPool)

for(i in range(guestPool.length)){
    for(j in range(metas.length)){
        if(guestPool[i] === metas[j]){
            guestPool[i] = '\\' + guestPool[i];
        }
    }
}

var guest = guestPool.join("");
return guest;
//console.log(guest)

}; };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM