Skip to content

Adds support for format operators in SQLQueryParameterization#361

Merged
andrecsilva merged 18 commits intomainfrom
sqlp-formatop
Mar 14, 2024
Merged

Adds support for format operators in SQLQueryParameterization#361
andrecsilva merged 18 commits intomainfrom
sqlp-formatop

Conversation

@andrecsilva
Copy link
Copy Markdown
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.

Comment thread src/codemodder/codemods/transformations/remove_empty_string_concatenation.py Outdated
Comment thread src/codemodder/utils/linearize_string_expression.py Outdated
Comment thread src/core_codemods/sql_parameterization.py
Comment thread src/core_codemods/sql_parameterization.py Outdated
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread src/core_codemods/sql_parameterization.py Outdated
@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
@sonarqubecloud
Copy link
Copy Markdown

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
@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