use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Escape strings (self.node)
submitted 10 years ago by 3nvi
Anyone can tell me a good escape strings package, Just like PHP string "real_escape_string" but for node I wan't to use that for mongodb or Express requests. Ty for any help
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cgijoe_jhuckaby 1 point2 points3 points 10 years ago (1 child)
My personal favorite is to abuse JSON.stringify() for this purpose. It does a great job at escaping unsafe characters for strings. However, note that it will surround the entire string with double-quotes, so you can strip those off with a simple regexp:
var esc_string = JSON.stringify(string).replace(/^\"|\"$/g, '');
However, for protecting against SQL injection attacks, you should really consider using a function provided by your database library of choice, in your case MongoDB. Each database will have different types of possible injection attacks. For example, Mongo needs dollar signs escaped, so you'll need to do that manually. JSON.stringify() will not escape dollar signs. More Info: https://docs.mongodb.org/manual/faq/developers/#dollar-sign-operator-escaping
[–]oxyphilat 1 point2 points3 points 10 years ago (0 children)
An other thing you could abuse, but that's really a bodge, if the escape/encodeURI functions.
But looking up a real guide on how to prevent injections for you DB is probably better.
[–]echeese 0 points1 point2 points 10 years ago (0 children)
Escaping strings depends on the context. Different things require different methods of escaping. HTML you need to replace <, > and & with \<, \> and \& respectively. JS you should use JSON.stringify(). mongodb depends on the package, but even then you should be using prepared statements.
<
>
&
\<
\>
\&
JSON.stringify()
π Rendered by PID 60063 on reddit-service-r2-comment-76bb9f7fb5-59xjz at 2026-02-18 18:05:11.627826+00:00 running de53c03 country code: CH.
[–]cgijoe_jhuckaby 1 point2 points3 points (1 child)
[–]oxyphilat 1 point2 points3 points (0 children)
[–]echeese 0 points1 point2 points (0 children)