Skip to content

Fix right(), left() length validation #2801

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 5 commits into from
Dec 29, 2022
Merged

Conversation

nafraf
Copy link
Contributor

@nafraf nafraf commented Dec 28, 2022

These changes are to fix bug #2798.

Changes:

  • The validations of length are done before validating if input string is null
  • Error message for invalid length was changed in functions left(), right(), and substring()

Sample output:

127.0.0.1:6379> GRAPH.QUERY g "RETURN right('a', null)"
(error) length must be a non-negative integer
127.0.0.1:6379> GRAPH.QUERY g "RETURN right(null, null)"
1) 1) "right(null, null)"
2) 1) 1) (nil)
127.0.0.1:6379> GRAPH.QUERY g "RETURN right(null, -1)"
1) 1) "right(null, -1)"
2) 1) 1) (nil)

Edit: Sample output updated with changes f917b06

@LiorKogan
Copy link
Member

LiorKogan commented Dec 28, 2022

Hi @nafraf
Thank you,
The output when both arguments are null should be null - not an error.

@codecov
Copy link

codecov bot commented Dec 28, 2022

Codecov Report

Base: 92.16% // Head: 92.18% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (f917b06) compared to base (6e339e9).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2801      +/-   ##
==========================================
+ Coverage   92.16%   92.18%   +0.02%     
==========================================
  Files         264      264              
  Lines       25093    25097       +4     
==========================================
+ Hits        23126    23136      +10     
+ Misses       1967     1961       -6     
Impacted Files Coverage Δ
src/arithmetic/string_funcs/string_funcs.c 99.33% <100.00%> (+3.35%) ⬆️
src/arithmetic/arithmetic_expression.c 93.39% <0.00%> (-0.46%) ⬇️
src/procedures/proc_ss_paths.c 91.27% <0.00%> (-0.30%) ⬇️
src/procedures/proc_sp_paths.c 96.84% <0.00%> (-0.29%) ⬇️
src/value.c 90.90% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@nafraf
Copy link
Contributor Author

nafraf commented Dec 28, 2022

@LiorKogan Thanks.
You are right, the description of the issue was clear for that case, it was my error, then Null is a valid type for second argument. I updated the sample outputs in first comment.

Is this the expected output in this case? Or the expected result is NULL?

127.0.0.1:6379> GRAPH.QUERY g "RETURN right(null, -1)"
(error) length must be a non-negative integer

@LiorKogan
Copy link
Member

LiorKogan commented Dec 28, 2022

@nafraf

127.0.0.1:6379> GRAPH.QUERY g "RETURN right(null, -1)"
(error) length must be a non-negative integer

Haha... The result is this pathological case should actually be null...

I guess this is just the order of the checks...

@nafraf nafraf marked this pull request as ready for review December 29, 2022 00:49
@nafraf
Copy link
Contributor Author

nafraf commented Dec 29, 2022

@LiorKogan
Change done. Validations are simpler now.
Thanks.

if(SIValue_IsNull(argv[0])) return SI_NullVal();

int64_t newlen = -1;
if(SI_TYPE(argv[1]) == T_INT64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not removing the null option for the second argument from the registration and then this if is not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because if null option is removed for second argument, the output of right(null, null) will be an error of type mismatch, but the expected output is NULL, without error.

@AviAvni AviAvni merged commit a0630c1 into RedisGraph:master Dec 29, 2022
@nafraf nafraf deleted the bug#2798 branch December 29, 2022 12:29
raz-mon pushed a commit that referenced this pull request Jan 25, 2023
* Fix AR_LEFT, AR_RIGHT length validation

* Test mistmatch type and fix error message

* left(), right(): NULL is a valid type for lenght

* Fix argument validation

Co-authored-by: Avi Avni <avi.avni@gmail.com>
AviAvni added a commit that referenced this pull request Jan 25, 2023
* Fix toInteger() and toIntegerOrNull() don't convert Booleans (#2797)

* AR_TOINTEGER: add case for type T_BOOL

* skip [8] toInteger() failing on invalid arguments

* Update TypeConversion2.feature

Co-authored-by: Avi Avni <avi.avni@gmail.com>

* Fix right(), left() length validation (#2801)

* Fix AR_LEFT, AR_RIGHT length validation

* Test mistmatch type and fix error message

* left(), right(): NULL is a valid type for lenght

* Fix argument validation

Co-authored-by: Avi Avni <avi.avni@gmail.com>

* fix using timeout max as default when default not configured (#2808)

* fix using timeout max as default when default not configured

* fix

* do not cache query params (#2803)

* do not cache query params

* address PR comments

* fix leak

* fix test

* convert params to SIValues

* wip

* delay freeing of parsed params to after the query is parsed

* free parse params when freeing AST

* revert changes to ast_validations.c

* revert arithmetic_expression_construct changes

* emit an error when param value eval fails

Co-authored-by: Avi Avni <avi.avni@gmail.com>

* fix multi-hop traverse with name path (#2743)

* Add varLen property to QGEdge

* Test variable-length edge queries

* Fix spacing

* Fix test, remove direction

* Fix test

* Test zero length edge

* Init varLen in QGEdge_New()

* rename varLen to rangeLen

* Rewrite test11_range_length_edges()

* Use QGEdge_VariableLength() and QGEdge_RangeLength

* Replace QGEdge_RangeLength() by QGEdge_LengthOne()

* rename function

Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
Co-authored-by: Avi Avni <avi.avni@gmail.com>

* indegree(), outdegree() - accept array of strings (#2807)

* _AR_NodeDegree() support T_ARRAY argument

* Add tests

* Fix argument validation

* Free array in case of error detected.

* Duplicate comments and use siarray.array[i]

* Update AR_IN() to use SI_ArrayContainsValue()

* Validate comparedNull pointer

* Support only the following two signatures:

* Test indegree() wrong argument number

* Test wrong signature: string and list

* clean

* revert

Co-authored-by: Avi Avni <avi.avni@gmail.com>

* Add ipv6 capability (#2842)

* fix heap remove item (#2827)

* fix heap remove item

* remove utf8 deps

* add test

* wip

* wip

* all unit tests pass

* heap remove element should use pointer cmp instead of cmp cb

* spaces to tabs

Co-authored-by: swilly22 <roi@redislabs.com>
Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>

* bump version 2.10.6

* Improve edge deletion performance (#2758)

* improve edge deletion

* update simple timer

* improve edge deletion perf

* fix build

* fix test

* fix test

* clean

* address review

Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>

* update ramp

Co-authored-by: nafraf <nafraf@users.noreply.github.com>
Co-authored-by: Avi Avni <avi.avni@gmail.com>
Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
Co-authored-by: Guy Korland <gkorland@gmail.com>
Co-authored-by: swilly22 <roi@redislabs.com>
pnxguide pushed a commit to CMU-SPEED/RedisGraph that referenced this pull request Mar 22, 2023
* Fix AR_LEFT, AR_RIGHT length validation

* Test mistmatch type and fix error message

* left(), right(): NULL is a valid type for lenght

* Fix argument validation

Co-authored-by: Avi Avni <avi.avni@gmail.com>
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.

3 participants