Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

clean_regex fails with int and bool values #51

Closed tissieres closed 7 years ago

tissieres commented 8 years ago

Hi, The clean_regex function added in the last commit expects only a str. But searchValue can be either a bool, a int or a str. A naive fix would be

if isinstance(searchValue, str):
  regex = clean_regex(searchValue)
else:
  regex = searchValue
Pegase745 commented 8 years ago

Thanks !

louking commented 8 years ago

Sorry about that -- I'm not clear what would cause datatables to send int or bool, but I think the fix looks fine in any case.

tissieres commented 8 years ago

The prepare_arguments function tries to convert the value it gets from the request to a int, a bool before keeping it as a str. If a user searches for the value "1", then it will be converted to int for example.

louking commented 8 years ago

In the process of fixing this. Easiest way is as follows at start of clean_regex

if not isinstance(regex, (str, unicode)):
    return regex

Need to check for (str, unicode) because object may be (is!) unicode. Note in Python > 3.0, unicode is set to str at top of __init__.py

tdamsma commented 7 years ago

Closing this as it doesn't apply to to the current version of sqlalchemy-datatables