From 85d2ff4d1c0e4fedfa90334d3fd31340422b3978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Miku=C5=A1?= Date: Thu, 7 Dec 2023 22:35:11 +0100 Subject: [PATCH] Trailing whitespaces discarded from assembly name. Improved AssemblyQualifiedName tests to test ranges. --- .../Binding/Parser/AssemblyNameBindingParserNode.cs | 10 +++------- .../Parser/Binding/Parser/BindingParser.cs | 8 ++++++-- src/Tests/Parser/Binding/BindingParserTests.cs | 12 +++++++++--- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Framework/Framework/Compilation/Parser/Binding/Parser/AssemblyNameBindingParserNode.cs b/src/Framework/Framework/Compilation/Parser/Binding/Parser/AssemblyNameBindingParserNode.cs index 781cb28972..5eeb249911 100644 --- a/src/Framework/Framework/Compilation/Parser/Binding/Parser/AssemblyNameBindingParserNode.cs +++ b/src/Framework/Framework/Compilation/Parser/Binding/Parser/AssemblyNameBindingParserNode.cs @@ -12,15 +12,11 @@ namespace DotVVM.Framework.Compilation.Parser.Binding.Parser public class AssemblyNameBindingParserNode : BindingParserNode { public string Name { get; } - public AssemblyNameBindingParserNode(List tokens) - { - Tokens = tokens; - Name = string.Concat(tokens.Select(t => t.Text)); - } public AssemblyNameBindingParserNode(string name) - : this(new List() { new BindingToken(name, BindingTokenType.Identifier, 0, 0, 0, 0)}) - { } + { + Name = name; + } public override IEnumerable EnumerateChildNodes() => Enumerable.Empty(); diff --git a/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs b/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs index c9347fcbb5..d975a4f5c2 100644 --- a/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs +++ b/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs @@ -148,12 +148,16 @@ public AssemblyNameBindingParserNode ReadAssemblyName() var startIndex = CurrentIndex; var tokens = Tokens.Skip(CurrentIndex).ToList(); - CurrentIndex = Tokens.Count; while (tokens.Count > 0 && tokens[tokens.Count - 1].Type == BindingTokenType.WhiteSpace) tokens.RemoveAt(tokens.Count - 1); - var node = CreateNode(new AssemblyNameBindingParserNode(tokens), startIndex); + CurrentIndex += tokens.Count; + var name = string.Concat(tokens.Select(t => t.Text)); + + var node = CreateNode(new AssemblyNameBindingParserNode(name), startIndex); + CurrentIndex = Tokens.Count; + if (node.Name.Length == 0) { node.NodeErrors.Add("Assembly name cannot be empty."); diff --git a/src/Tests/Parser/Binding/BindingParserTests.cs b/src/Tests/Parser/Binding/BindingParserTests.cs index 6d96e5ff00..65413f5612 100644 --- a/src/Tests/Parser/Binding/BindingParserTests.cs +++ b/src/Tests/Parser/Binding/BindingParserTests.cs @@ -864,13 +864,19 @@ public void BindingParser_ArrayType_ValidAssemblyName(string binding) [DataRow("Domain.Company.Product.DotVVM.Feature.Type, Domain.Company.Product", "Domain.Company.Product")] [DataRow("Domain.Company.Product.DotVVM.Feature.Type, Domain.Company.Product", "Domain.Company.Product")] [DataRow("Domain.Company.Product.DotVVM.Feature.Type, Product", "Product")] + [DataRow("Domain.Company.Product.DotVVM.Feature.Type, Product ", "Product")] + [DataRow("Domain.Company.Product.DotVVM.Feature.Type, my assembly name ", "my assembly name")] public void BindingParser_AssemblyQualifiedName_ValidAssemblyName(string binding, string assemblyName) { var parser = bindingParserNodeFactory.SetupParser(binding); var node = parser.ReadDirectiveTypeName() as AssemblyQualifiedNameBindingParserNode; + + var controlSting = binding.TrimEnd(); + Assert.IsFalse(node.AssemblyName.HasNodeErrors); - Assert.AreEqual(assemblyName, node.AssemblyName.ToDisplayString()); + AssertNode(node, controlSting, 0, binding.Length); + AssertNode(node.AssemblyName, assemblyName, 44, assemblyName.Length); } [TestMethod] @@ -1217,7 +1223,7 @@ public void BindingParser_PropertyHalfWrittenAttributes() Assert.AreEqual(4, root.Attributes.Count); var emptyAttribute = root.Attributes[0].CastTo(); - AssertNode(emptyAttribute, "", 19, 0, hasErrors:true); + AssertNode(emptyAttribute, "", 19, 0, hasErrors: true); var dotvvmNode = root.Attributes[1].CastTo(); AssertNode(dotvvmNode, "DotVVM.", 21, 7); @@ -1495,7 +1501,7 @@ private static void AssertNode(BindingParserNode node, string expectedDisplayStr } else { - Assert.IsFalse (node.HasNodeErrors); + Assert.IsFalse(node.HasNodeErrors); } }