Skip to content

Commit b95ac22

Browse files
authored
properly escaping queries with forward slashes (#322)
1 parent 8d05d91 commit b95ac22

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/Redis.OM/Common/ExpressionParserUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal static class ExpressionParserUtilities
2626
private static readonly char[] TagEscapeChars =
2727
{
2828
',', '.', '<', '>', '{', '}', '[', ']', '"', '\'', ':', ';',
29-
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', ' ',
29+
'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', ' ', '/',
3030
};
3131

3232
/// <summary>

test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,15 @@ public void TestIntSelects()
10081008
collection.Delete(obj);
10091009
}
10101010

1011+
[Fact]
1012+
public void TestQueryWithForwardSlashes()
1013+
{
1014+
var collection = new RedisCollection<ObjectWithZeroStopwords>(_connection);
1015+
collection.Insert(new ObjectWithZeroStopwords() { Name = "a/test/string" });
1016+
1017+
Assert.NotNull(collection.FirstOrDefault(x=>x.Name == "a/test/string"));
1018+
}
1019+
10111020
[Fact]
10121021
public void TestComplexObjectsWithMixedNesting()
10131022
{

test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,24 @@ public void TestNullableEnumQueries()
28892889
));
28902890
}
28912891

2892+
[Fact]
2893+
public void TestEscapeForwardSlash()
2894+
{
2895+
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
2896+
.Returns(_mockReply);
2897+
2898+
var collection = new RedisCollection<Person>(_mock.Object);
2899+
collection.Where(x => x.TagField == "a/test/string").ToList();
2900+
_mock.Verify(x => x.Execute(
2901+
"FT.SEARCH",
2902+
"person-idx",
2903+
"(@TagField:{a\\/test\\/string})",
2904+
"LIMIT",
2905+
"0",
2906+
"100"
2907+
));
2908+
}
2909+
28922910
[Fact]
28932911
public void TestMixedNestingIndexCreation()
28942912
{

0 commit comments

Comments
 (0)