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

Dev-550: (bugfix) Making sure variable is used properly in query #277

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

mwarin
Copy link
Contributor

@mwarin mwarin commented Jun 5, 2023

Diff, essentially:

- w
+ W

That is to say, what has functionally changed is a non-interpolating %w[...] was changed into an interpolating %W[...]. The changed code was broken out into its own method (query) so I could write a simple test to make it obvious that interpolation happened.

@coveralls
Copy link

coveralls commented Jun 5, 2023

Coverage Status

coverage: 95.137% (-0.02%) from 95.159% when pulling 563faef on DEV-550-bugfix into e1261a5 on main.

@mwarin mwarin requested review from aelkiss and moseshll June 5, 2023 18:27
Copy link
Member

@aelkiss aelkiss left a comment

Choose a reason for hiding this comment

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

A couple thoughts: while this appears correct, it's an unusual construction (I don't know that I've ever seen %W before) and is insecure - given that start_date is passed in from the outside this is in theory vulnerable to sql injection. Best practice is to use a SQL placeholder for start_date. If we want a multi-line string I would prefer using a heredoc (mariadb shouldn't care about the extra whitespace):

QUERY = <<~SQL
        SELECT
        CONCAT(namespace, '.', id) AS ht_id,
        MIN(DATE_FORMAT(time, "%Y-%m-%d")) AS min_time
        FROM
        rights_log
        GROUP BY
        namespace, id
        HAVING
        MIN(time) >= ?
SQL

along with:

  db.fetch(QUERY,@start_date) do |row|
    ...
  end

(see https://www.rubydoc.info/gems/sequel/4.38.0/Sequel%2FDatabase:fetch)

@mwarin mwarin requested a review from aelkiss June 6, 2023 15:57
@mwarin mwarin changed the title Dev-550: (bugfix) Making sure variable is interpolated in query Dev-550: (bugfix) Making sure variable is used properly in query Jun 6, 2023
Copy link
Member

@aelkiss aelkiss left a comment

Choose a reason for hiding this comment

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

Looks good now - thanks

Copy link
Contributor

@moseshll moseshll left a comment

Choose a reason for hiding this comment

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

Three cheers for here docs.

@mwarin mwarin merged commit 38a252b into main Jun 6, 2023
@aelkiss aelkiss deleted the DEV-550-bugfix branch January 7, 2025 20:38
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.

4 participants