Skip to content
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

fix(bind): add escsape of null character for postgres bind parameters #10716

Merged
merged 1 commit into from Apr 8, 2019

Conversation

holm
Copy link
Contributor

@holm holm commented Apr 7, 2019

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Postgres doesn't support null characters in strings. This has generally been handled via https://github.com/sequelize/sequelize/blob/master/lib/sql-string.js#L75. However with Sequelize 5 using bind parameters for insert and update, the replacement of null characters no longer happens. This PR adds replacement of null characters in case of bind parameters being used.

I have added tests, but have not been able to run them across the other database. I think it should pass though, otherwise I would appreciate help getting them fixed.

@codecov
Copy link

codecov bot commented Apr 7, 2019

Codecov Report

Merging #10716 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10716      +/-   ##
==========================================
+ Coverage    96.3%    96.3%   +<.01%     
==========================================
  Files          93       93              
  Lines        8976     8980       +4     
==========================================
+ Hits         8644     8648       +4     
  Misses        332      332
Impacted Files Coverage Δ
lib/dialects/postgres/query.js 97.72% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6c9117...b30431f. Read the comment docs.

@@ -20,11 +20,20 @@ class Query extends AbstractQuery {
* @private
*/
static formatBindParameters(sql, values, dialect) {
let bindParam = [];
const stringReplaceFunc = value => {
if (_.isString(value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You can make this value => typeof value === 'string' ? value.replace(...) : value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that wasn’t a complete check due to the issues explained at https://stackoverflow.com/questions/4059147/check-if-a-variable-is-a-string-in-javascript

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the codebase already uses typeof checks, https://stackoverflow.com/questions/5750656/whats-the-point-of-new-stringx-in-javascript explains the debacle pretty well.

In the end, sequelize doesn't really support these boxed types and I don't think it should as it would increase complexity in hundreds of places.

Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than the comment of @SimonSchick lgtm

@holm
Copy link
Contributor Author

holm commented Apr 8, 2019

I addressed the comment now. The build failure doesn't seem related to my changes.

@sushantdhiman sushantdhiman merged commit d6daaf1 into sequelize:master Apr 8, 2019
@sushantdhiman
Copy link
Contributor

🎉 This PR is included in version 5.2.13 🎉

The release is available on:

Your semantic-release bot 📦🚀

@holm
Copy link
Contributor Author

holm commented Apr 9, 2019

Thanks for the quick merge and release

@holm holm deleted the fix/postgres_escape branch April 9, 2019 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants