-
Notifications
You must be signed in to change notification settings - Fork 228
Fix integer out of range #284
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
Fix integer out of range #284
Conversation
Hi! Thanks for your contribution! There are some changes to do before I can merge it. Also can you please rebase on master? Thank you! |
Hey @n-rodriguez - What do you mean by rebase? Do you want me to squash the three commits of mine so that it is only one? That should be available in the dropdown when you merge the PR through the UI. But if you mean something else, hit me up. What changes do you need to be done? Maybe I can spend some more time. |
Hi! I mean merging the last commits I've made into your branch. But since it's a rebase it's gonna take my commits first then apply yours. It works like that :
You'll have to do |
4fcc4a2
to
c7f3c6f
Compare
Hey @n-rodriguez. Thanks for the small tour on rebasing - I've followed it and pushed everything :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some changes to do before I can merge it. Thank you?
@@ -49,12 +52,20 @@ def regex_search | |||
end | |||
end | |||
|
|||
def empty_search | |||
casted_column.matches("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of simple quote is recommanded
empty_search | ||
else | ||
numeric_search | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more readable if you invert the logic :
if is_searchable_integer?
numeric_search
else
empty_search
end
table.engine.columns_hash[field.to_s].sql_type == 'integer' && is_integer?(search.value) && is_out_of_range?(search.value) | ||
end | ||
|
||
def is_out_of_range? search_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add parenthesis around arguments
@@ -82,6 +93,18 @@ def numeric_search | |||
end | |||
end | |||
|
|||
def is_searchable_integer? | |||
return false unless table.respond_to?(:engine) | |||
table.engine.columns_hash[field.to_s].sql_type == 'integer' && is_integer?(search.value) && is_out_of_range?(search.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invert the last test to match with the previous recommandation :
def is_searchable_integer?
return false unless table.respond_to?(:engine)
table.engine.columns_hash[field.to_s].sql_type == 'integer' && is_integer?(search.value) && !is_out_of_range?(search.value)
end
All change requests have been added and the tests are still running fine (on my end: |
881e955
to
fc1c987
Compare
Hi! Tests are failing for Rails < 5.x. Can you please take a look? |
Hi! There is something wrong with your implementation. |
@@ -82,6 +89,18 @@ def numeric_search | |||
end | |||
end | |||
|
|||
def is_searchable_integer? | |||
return true unless table.respond_to?(:engine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This always return true on Rails 5.x because table doesn't respond to :engine
@@ -82,6 +89,18 @@ def numeric_search | |||
end | |||
end | |||
|
|||
def is_searchable_integer? | |||
return true unless table.respond_to?(:engine) | |||
table.engine.columns_hash[field.to_s].sql_type == 'integer' && is_integer?(search.value) && !is_out_of_range?(search.value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You get to this point on Rails 4 but is_out_of_range?
always return false because it (can) receives an array of integer and is_integer?(string)
shadows the casting error by rescuing to false.
1) AjaxDatatablesRails::ORM::ActiveRecord filter conditions it can filter records with condition :in should filter records matching
Failure/Error: Integer(search_value) > LARGEST_PQ_INTEGER || Integer(search_value) < SMALLEST_PQ_INTEGER
TypeError:
can't convert Array into Integer
Actually your PR does nothing. |
e975b07
to
bd0393b
Compare
Ok, I think you forgot to create a DB field with a limited int size. By default Rails use int(11) on 4.2 and bigint on 5.x so no error is triggered with your tests and the default config. |
Ok, it turns out you're using the wrong datatable in tests so it's doesn't use |
@@ -387,6 +387,32 @@ | |||
end | |||
end | |||
|
|||
describe 'Integer overflows' do | |||
let(:largest_postgresql_integer_value) { 2147483647 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It misses let(:datatable) { DatatableCondEq.new(view) }
Hey. Thank you for the effort. I am sorry I did not reply, was quite busy these days (plus there were a lot of holidays in Germany this month ;)). |
Thank you too, you found it 🎉 I realized latter I could have merged your PR and make the fixes right after... sorry |
Hi folks!
We've lately had a few users trying to search for values that were not meant to be searched but still caused datatables to try and search for it. This lead to this error
This issue only applies to
:eq
searches and only if it's an integer value that's stored in this very column.Maybe this PR is of use. If not, have it removed please 👍