From b95ac2244ad5377fdf813564ca2b658e1e6c882b Mon Sep 17 00:00:00 2001 From: Steve Lorello <42971704+slorello89@users.noreply.github.com> Date: Tue, 14 Mar 2023 08:23:38 -0400 Subject: [PATCH] properly escaping queries with forward slashes (#322) --- .../Common/ExpressionParserUtilities.cs | 2 +- .../RediSearchTests/SearchFunctionalTests.cs | 9 +++++++++ .../RediSearchTests/SearchTests.cs | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Redis.OM/Common/ExpressionParserUtilities.cs b/src/Redis.OM/Common/ExpressionParserUtilities.cs index 8ce09d16..a4e66e04 100644 --- a/src/Redis.OM/Common/ExpressionParserUtilities.cs +++ b/src/Redis.OM/Common/ExpressionParserUtilities.cs @@ -26,7 +26,7 @@ internal static class ExpressionParserUtilities private static readonly char[] TagEscapeChars = { ',', '.', '<', '>', '{', '}', '[', ']', '"', '\'', ':', ';', - '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', ' ', + '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '~', '|', ' ', '/', }; /// diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs index 5134f165..0a1dc90a 100644 --- a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs +++ b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs @@ -1008,6 +1008,15 @@ public void TestIntSelects() collection.Delete(obj); } + [Fact] + public void TestQueryWithForwardSlashes() + { + var collection = new RedisCollection(_connection); + collection.Insert(new ObjectWithZeroStopwords() { Name = "a/test/string" }); + + Assert.NotNull(collection.FirstOrDefault(x=>x.Name == "a/test/string")); + } + [Fact] public void TestComplexObjectsWithMixedNesting() { diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs index 36767f40..40564d0c 100644 --- a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs +++ b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs @@ -2889,6 +2889,24 @@ public void TestNullableEnumQueries() )); } + [Fact] + public void TestEscapeForwardSlash() + { + _mock.Setup(x => x.Execute(It.IsAny(), It.IsAny())) + .Returns(_mockReply); + + var collection = new RedisCollection(_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() {