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

Raw operator does not properly escape nested columns #6264

Closed
ouzkhanmete opened this issue Jun 16, 2020 · 1 comment · Fixed by #7805
Closed

Raw operator does not properly escape nested columns #6264

ouzkhanmete opened this issue Jun 16, 2020 · 1 comment · Fixed by #7805

Comments

@ouzkhanmete
Copy link

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 11.5 (or put your version here)

Steps to reproduce or a small repository showing the problem:

Currently Raw operator is broken when using joins. columnPath that is passed in callback has a value of "SomeTable.someColumn" which resolved with an error missing from-clause entry for table when executing a query.

Example:

// This is broken
repo.findOne({
  where: {
    field: Raw(columnPath => `${columnPath} = "somevalue"`)
  },
  relation: ['someOtherTable']
})


// This works
function wrapColumnPath(columnPath: string): string {
    return columnPath.split('.').map(c => `"${c}"`).join('.')
}

repo.findOne({
  where: {
    field: Raw(columnPath => `${wrapColumnPath(columnPath)} = "somevalue"`)
  },
  relation: ['someOtherTable']
})

As mentioned in this issue we should have some sort of SafeRaw to handle this kind of issues.

@imnotjames imnotjames changed the title Raw operator is broken Raw operator does not properly escape nested columns Oct 5, 2020
@imnotjames imnotjames self-assigned this Oct 27, 2020
@imnotjames
Copy link
Contributor

The issue isn't that it isn't escaped - the issue is that the replacement that happens later on in the query building process doesn't replace it with the escaped value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants