Skip to content

Escape backslashes in RedisGraphUtilities.PrepareQuery #155

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
Jul 2, 2023

Conversation

haysch
Copy link
Contributor

@haysch haysch commented Jul 1, 2023

Context

The current implementation does not factor in the use of \ in strings.
By adding a backslash as the last character in a Cypher string parameter, the query will fail, i.e., by doing the following in the PR:

  1. When providing the string parameter abc\
  2. Removing the replacing in RedisGraphUtilities.QuoteString
  3. Removing the prepared query string Assert.Equal(expectedPreparedQuery9, preparedQuery9);

The query will fail with:

StackExchange.Redis.RedisServerException : errMsg: Invalid input 'a': expected ';', ':', a statement option, a query hint, a clause or a schema command line: 1, column: 1, offset: 0 errCtx: a="abc\" RETURN 1 errCtxOffset: 0

Solution

Escaping backslashes when preparing Cypher queries.

The order of escaping is important to avoid escaping the backslashes produced by escaping ".

haysch added 2 commits July 1, 2023 14:22
* Escape backslashes in strings.
* Add test cases for PrepareQuery.
@chayim chayim added the bug Something isn't working label Jul 2, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 2, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (dfb621d) 93.48% compared to head (9c14898) 93.49%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #155   +/-   ##
=======================================
  Coverage   93.48%   93.49%           
=======================================
  Files          78       78           
  Lines        4775     4782    +7     
  Branches      450      450           
=======================================
+ Hits         4464     4471    +7     
  Misses        185      185           
  Partials      126      126           
Impacted Files Coverage Δ
src/NRedisStack/Graph/GraphCommandBuilder.cs 95.00% <100.00%> (+0.55%) ⬆️
src/NRedisStack/Graph/RedisGraphUtilities.cs 91.13% <100.00%> (+0.34%) ⬆️

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

@shacharPash
Copy link
Contributor

@haysch Thanks for the contribution, Looks good 👍
Just changed the PR so that the internals are not visible to the tests.

Copy link
Contributor

@shacharPash shacharPash left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@shacharPash shacharPash merged commit 50a0740 into redis:master Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants