Skip to content

Commit

Permalink
properly escaping queries with forward slashes (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 authored Mar 14, 2023
1 parent 8d05d91 commit b95ac22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Redis.OM/Common/ExpressionParserUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal static class ExpressionParserUtilities
private static readonly char[] TagEscapeChars =
{
',', '.', '<', '>', '{', '}', '[', ']', '"', '\'', ':', ';',
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', ' ',
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', ' ', '/',
};

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,15 @@ public void TestIntSelects()
collection.Delete(obj);
}

[Fact]
public void TestQueryWithForwardSlashes()
{
var collection = new RedisCollection<ObjectWithZeroStopwords>(_connection);
collection.Insert(new ObjectWithZeroStopwords() { Name = "a/test/string" });

Assert.NotNull(collection.FirstOrDefault(x=>x.Name == "a/test/string"));
}

[Fact]
public void TestComplexObjectsWithMixedNesting()
{
Expand Down
18 changes: 18 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2889,6 +2889,24 @@ public void TestNullableEnumQueries()
));
}

[Fact]
public void TestEscapeForwardSlash()
{
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
.Returns(_mockReply);

var collection = new RedisCollection<Person>(_mock.Object);
collection.Where(x => x.TagField == "a/test/string").ToList();
_mock.Verify(x => x.Execute(
"FT.SEARCH",
"person-idx",
"(@TagField:{a\\/test\\/string})",
"LIMIT",
"0",
"100"
));
}

[Fact]
public void TestMixedNestingIndexCreation()
{
Expand Down

0 comments on commit b95ac22

Please sign in to comment.