-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Do not concatenate an array if passed to escapeLiteral #3489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,14 @@ const escapeLiteral = function (str) { | |
let hasBackslash = false | ||
let escaped = "'" | ||
|
||
if (str == null) { | ||
return "''" | ||
} | ||
|
||
if (typeof str !== 'string') { | ||
return "''" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about throwing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's what i was going to do at first, but after writing a bunch of tests for previously indeterminate behavior, almost everything returned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you mention those examples... how about casting everything to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that isn't a good idea - def breakage, though subtle. tbh whenever I, very rarely, use these functions to concatenate some form of user-input into a query directly I do a ton of external sanitization first. Check types, if its a number make sure its in an expected range, etc. It's scary & should be a last resort in most cases. |
||
} | ||
|
||
for (let i = 0; i < str.length; i++) { | ||
const c = str[i] | ||
if (c === "'") { | ||
|