Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public SimplePathExpressionBindingProperty FormatSimplePath(IBinding binding)
// if contains api parameter, can't use this as a path
if (js.Expression.DescendantNodes().Any(n => n.TryGetAnnotation(out ViewModelInfoAnnotation? vmInfo) && vmInfo.ExtensionParameter is RestApiRegistrationHelpers.ApiExtensionParameter apiParameter))
throw new Exception($"Can't get a path expression for command binding from binding that is using rest api.");
return new(js.Expression.FormatParametrizedScript());
var expr = js.Expression.Clone(); // need to Clone, because js.Expression is frozen and not parethesized
return new(expr.FormatParametrizedScript());
}
else if (binding.GetProperty<KnockoutExpressionBindingProperty>(ErrorHandlingMode.ReturnNull) is { } expr)
{
Expand Down
32 changes: 24 additions & 8 deletions src/Tests/Binding/JavascriptCompilationTests.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
using DotVVM.Framework.Binding;
using DotVVM.Framework.Controls;
using DotVVM.Framework.Runtime;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Binding.Expressions;
using DotVVM.Framework.Binding.Properties;
using DotVVM.Framework.Compilation;
using DotVVM.Framework.Compilation.Binding;
using DotVVM.Framework.Compilation.ControlTree;
using DotVVM.Framework.Compilation.Javascript;
using DotVVM.Framework.Compilation.Javascript.Ast;
using DotVVM.Framework.Testing;
using DotVVM.Framework.Configuration;
using System.Linq.Expressions;
using Microsoft.Extensions.DependencyInjection;
using DotVVM.Framework.Controls;
using DotVVM.Framework.Runtime;
using DotVVM.Framework.Testing;
using DotVVM.Framework.Utils;
using DotVVM.Framework.ViewModel;
using System.Text.Json.Serialization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static DotVVM.Framework.Configuration.FreezableUtils;

namespace DotVVM.Framework.Tests.Binding
{
Expand Down Expand Up @@ -1511,6 +1514,19 @@ public void JavascriptCompilation_StringFunctions(string input, string expected)
Assert.AreEqual(expected, result);
}

[TestMethod]
[DataRow("VmArray.Where(v => string.IsNullOrEmpty(v.SomeString)).ToList()")]
[DataRow("VmArray.Where(v => string.IsNullOrWhiteSpace(v.SomeString)).ToList()")]
// Regression test: FormatParametrizedScript was called on a frozen JsBinaryExpression (from string.IsNullOrEmpty/IsNullOrWhiteSpace
// translation) causing ObjectIsFrozenException when computing SimplePathExpressionBindingProperty.
public void JavascriptCompilation_IsNullOrEmpty_InWhereLambda_DoesNotThrowOnSimplePathExpression(string expression)
{
var binding = bindingHelper.ValueBinding<IEnumerable<TestViewModel2>>(
expression,
new[] { typeof(TestViewModel) });
var simplePath = binding.GetProperty(typeof(SimplePathExpressionBindingProperty), ErrorHandlingMode.ThrowException);
}

[TestMethod]
public void JavascriptCompilation_CustomPrimitiveToString()
{
Expand Down
Loading