diff --git a/src/Redis.OM/Modeling/JsonDiff.cs b/src/Redis.OM/Modeling/JsonDiff.cs index 672a41cb..e2516903 100644 --- a/src/Redis.OM/Modeling/JsonDiff.cs +++ b/src/Redis.OM/Modeling/JsonDiff.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System.Web; using Newtonsoft.Json.Linq; namespace Redis.OM.Modeling @@ -33,7 +34,7 @@ public string[] SerializeScriptArgs() { return _value.Type switch { - JTokenType.String => new[] { _operation, _path, $"\"{_value}\"" }, + JTokenType.String => new[] { _operation, _path, $"\"{HttpUtility.JavaScriptStringEncode(_value.ToString())}\"" }, JTokenType.Boolean => new[] { _operation, _path, _value.ToString().ToLower() }, _ => new[] { _operation, _path, _value.ToString() } }; diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs index 1a272ab1..551ede8f 100644 --- a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs +++ b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchFunctionalTests.cs @@ -148,13 +148,17 @@ public void TestBasicQuerySpecialCharacters() [Fact] public void TestSave() { - var collection = new RedisCollection(_connection, 10000); + var collection = new RedisCollection(_connection, 10000); + + for(var i = 0; i < 10; i++) + { + collection.Insert(new BasicJsonObjectTestSave() { Name = "TestSaveBefore" }); + } var count = 0; foreach (var person in collection) { count++; person.Name = "TestSave"; - person.Mother = new Person { Name = "Diane" }; } collection.Save(); @@ -1003,5 +1007,17 @@ public void TestIntSelects() Assert.NotEmpty(res); collection.Delete(obj); } + + [Fact] + public void TestUpdateWithQuotes() + { + var obj = new BasicJsonObject() { Name = "Bob" }; + var collection = new RedisCollection(_connection); + collection.Insert(obj); + var reconstituted = collection.FindById(obj.Id); + reconstituted.Name = "\"Bob"; + collection.Update(reconstituted); + collection.Delete(obj); + } } } \ No newline at end of file diff --git a/test/Redis.OM.Unit.Tests/RedisSetupCollection.cs b/test/Redis.OM.Unit.Tests/RedisSetupCollection.cs index 4c65deb3..27e4de6c 100644 --- a/test/Redis.OM.Unit.Tests/RedisSetupCollection.cs +++ b/test/Redis.OM.Unit.Tests/RedisSetupCollection.cs @@ -26,6 +26,7 @@ public RedisSetup() Connection.CreateIndex(typeof(ObjectWithDateTime)); Connection.CreateIndex(typeof(ObjectWithDateTimeHash)); Connection.CreateIndex(typeof(PersonWithNestedArrayOfObject)); + Connection.CreateIndex(typeof(BasicJsonObjectTestSave)); } private IRedisConnection _connection = null; @@ -60,6 +61,7 @@ public void Dispose() Connection.DropIndexAndAssociatedRecords(typeof(ObjectWithDateTime)); Connection.DropIndexAndAssociatedRecords(typeof(ObjectWithDateTimeHash)); Connection.DropIndexAndAssociatedRecords(typeof(PersonWithNestedArrayOfObject)); + Connection.DropIndexAndAssociatedRecords(typeof(BasicJsonObjectTestSave)); } } } diff --git a/test/Redis.OM.Unit.Tests/Serialization/BasicJsonObject.cs b/test/Redis.OM.Unit.Tests/Serialization/BasicJsonObject.cs index f555eb97..4792ec76 100644 --- a/test/Redis.OM.Unit.Tests/Serialization/BasicJsonObject.cs +++ b/test/Redis.OM.Unit.Tests/Serialization/BasicJsonObject.cs @@ -8,4 +8,12 @@ public class BasicJsonObject [RedisIdField] public string Id { get; set; } public string Name { get; set; } +} + +[Document(StorageType = StorageType.Json)] +public class BasicJsonObjectTestSave +{ + [RedisIdField] + public string Id { get; set; } + [Indexed]public string Name { get; set; } } \ No newline at end of file