Browse Source

Fix Engine.SetValue(string, string) to check for null value (#1490)

Marko Lahma 2 years ago
parent
commit
4ebc6a03ed
2 changed files with 8 additions and 1 deletions
  1. 7 0
      Jint.Tests/Runtime/EngineTests.cs
  2. 1 1
      Jint/Engine.cs

+ 7 - 0
Jint.Tests/Runtime/EngineTests.cs

@@ -184,6 +184,13 @@ namespace Jint.Tests.Runtime
             ");
         }
 
+        [Fact]
+        public void ShouldAllowNullAsStringValue()
+        {
+            var engine = new Engine().SetValue("name", (string) null);
+            Assert.True(engine.Evaluate("name").IsNull());
+        }
+
         [Fact]
         public void FunctionConstructorsShouldCreateNewObjects()
         {

+ 1 - 1
Jint/Engine.cs

@@ -197,7 +197,7 @@ namespace Jint
         /// </summary>
         public Engine SetValue(string name, string value)
         {
-            return SetValue(name, JsString.Create(value));
+            return SetValue(name, value is null ? JsValue.Null : JsString.Create(value));
         }
 
         /// <summary>