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

Adds support for format operators in SQLQueryParameterization #361

Merged
merged 18 commits into from
Mar 14, 2024

Conversation

andrecsilva
Copy link
Contributor

@andrecsilva andrecsilva commented Mar 12, 2024

Overview

SQLQueryParameterization will now parameterize queries built with the format operator %

Description

  • SQLQueryParameterization will now correctly parameterize queries built with the format operator %;
  • Added LinearizeStringExpression. It takes a string expression and finds all the pieces that composes that string. For example: "1" + a + "2" will return a list with the nodes that represents "1", a and "2";
  • Added RemoveUnusedVariables. It removes local assignments that are not referenced anywhere else;
  • Added several utilities for parsing printf style strings in format_string_parser module;

Tackles #301.

Copy link
Member

@drdavella drdavella left a comment

Choose a reason for hiding this comment

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

This looks great overall. It's a lot of very impressive work, thanks for the effort.

I'm starting to see how some of these pieces could be taken and reused for other kinds of codemods (e.g. xpath injection).

}


def parse_formatted_string(
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty heroic, nice work. I could have sworn that there was something in the standard library that helped to tokenize format strings but I'm having trouble digging it up right now.

src/core_codemods/sql_parameterization.py Outdated Show resolved Hide resolved
@andrecsilva andrecsilva enabled auto-merge March 13, 2024 14:18
@andrecsilva andrecsilva added this pull request to the merge queue Mar 13, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 13, 2024
Copy link

Quality Gate Passed Quality Gate passed

Issues
13 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
2.0% Duplication on New Code

See analysis details on SonarCloud

@andrecsilva andrecsilva added this pull request to the merge queue Mar 14, 2024
Merged via the queue into main with commit ef74258 Mar 14, 2024
11 checks passed
@andrecsilva andrecsilva deleted the sqlp-formatop branch March 14, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants