-
Notifications
You must be signed in to change notification settings - Fork 1
fix: add validation and conversion types #13
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
base: master
Are you sure you want to change the base?
Conversation
При сравнении числа с булево, выдавало ошибку т.к. tonumber не мог привести его к числу. Добавил проверки на типы, преобразование булева в число и обратно. Исключил арифметические операции с булево и сравнения с строковым типом.
5c53414 to
311502d
Compare
jsonpath.lua
Outdated
| return nil, err | ||
| end | ||
| if operator == '+' then | ||
| if is_bool(op1) or is_bool(op2) then |
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.
Предложу заменить условие в этих арифметических операциях на "op1 и op2 должны быть строкой или числом", то есть не запретить булевы значения, а разрешить только числа и строки.
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.
Готово
jsonpath.lua
Outdated
| -- null must never be equal to other boolean, invert op1 | ||
| return not op1 | ||
| else | ||
| if type(op2) == 'string' then |
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.
- Переименовать match_type в match_cmp_type, так как эта функция используется только для приведения типов при операциях сравнения.
- Можно добавить из нее второй результат с ошибкой, чтобы сигнализировать о том, что операнды не сравнимы.
- После пункта 2 перенести в нее логику гарда (is_null or is_bool) -> false через выдачу ошибки
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.
готово
При сравнении числа с булево, выдавало ошибку т.к. tonumber не мог привести его к числу. Добавил проверки на типы, преобразование булева в число и обратно. Исключил арифметические операции с булево и сравнения с строковым типом.