Skip to content

improved sql comment handling #73

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

Merged
merged 3 commits into from
Sep 21, 2018
Merged

Conversation

igorwwwwwwwwwwwwwwwwwwww
Copy link
Contributor

This is an improved version of #56.

@igorwwwwwwwwwwwwwwwwwwww
Copy link
Contributor Author

igorwwwwwwwwwwwwwwwwwwww commented Sep 21, 2018

Please note that the tests are currently not passing when run on travis (https://travis-ci.org/travis-ci/marginalia/jobs/431465306). Possibly due to the dependency on the old mysql gem.

It also looks like the tests haven't been enabled for a while now though. So fixing that seems out of scope for this patch.

I was able to successfully run the tests locally via:

DRIVER=sqlite3 ruby -Ilib -Itest test/*_test.rb

ret
end

def self.escape_sql_comment(str)
str = str.dup
Copy link
Collaborator

@arthurnn arthurnn Sep 21, 2018

Choose a reason for hiding this comment

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

Can't we only dup if the str includes the patterns bellow? I want to save the extra allocation if not needed.

@igorwwwwwwwwwwwwwwwwwwww
Copy link
Contributor Author

I've made the dup conditional. In fact I'm not sure if it is even needed. Since the gsub should not modify the original. So we may be able to drop the dup completely.

def self.escape_sql_comment(str)
if str.include?('/*') || str.include?('*/')
str = str.dup
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right, we don't need the dup. gsub should already create a new string for us.

@igorwwwwwwwwwwwwwwwwwwww
Copy link
Contributor Author

Removed the dup.

@arthurnn arthurnn merged commit 36d4d75 into basecamp:master Sep 21, 2018
@arthurnn
Copy link
Collaborator

Thanks. i am cleaning up test and releasing a new gem version

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.

2 participants