Skip to content

Commit

Permalink
Fix loc and wix variables to allow dots in their identifier name again
Browse files Browse the repository at this point in the history
Fixes 8713
  • Loading branch information
robmen committed Dec 26, 2024
1 parent 95701cc commit b1e207c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/wix/WixToolset.Core/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ internal static bool TryParseWixVariable(string value, int start, out ParsedWixV

var equalsDefaultValue = value.IndexOf('=', firstDot + 1, closeParen - firstDot);
var end = equalsDefaultValue == -1 ? closeParen : equalsDefaultValue;
var secondDot = value.IndexOf('.', firstDot + 1, end - firstDot);
// bind variables may have a second dot to define their scope, other variables do not have scope and ignore additional dots.
var secondDot = ns == "bind" ? value.IndexOf('.', firstDot + 1, end - firstDot) : -1;

if (secondDot == -1)
{
Expand Down
17 changes: 12 additions & 5 deletions src/wix/test/WixToolsetTest.Core/VariableResolverFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WixToolsetTest.Core
{
using System.Collections.Generic;
using System.Linq;
using WixInternal.TestSupport;
using WixToolset.Core;
using WixToolset.Data;
Expand All @@ -18,12 +19,14 @@ public void CanRecursivelyResolveVariables()
var serviceProvider = WixToolsetServiceProviderFactory.CreateServiceProvider();
var variableResolver = serviceProvider.GetService<IVariableResolver>();

var variables = new Dictionary<string, BindVariable>()
var variables = new BindVariable[]
{
{ "ProductName", new BindVariable() { Id = "ProductName", Value = "Localized Product Name" } },
{ "ProductNameEdition", new BindVariable() { Id = "ProductNameEdition", Value = "!(loc.ProductName) Enterprise Edition" } },
{ "ProductNameEditionVersion", new BindVariable() { Id = "ProductNameEditionVersion", Value = "!(loc.ProductNameEdition) v1.2.3" } },
};
new() { Id = "ProductName", Value = "Localized Product Name" },
new() { Id = "ProductNameEdition", Value = "!(loc.ProductName) Enterprise Edition" },
new() { Id = "ProductNameEditionVersion", Value = "!(loc.ProductNameEdition) v1.2.3" },
new() { Id = "Dotted.Loc.Variable", Value = "Dotted.Loc.Variable = !(loc.ProductNameEditionVersion)" },
new() { Id = "NestedDotted.Loc.Variable", Value = "!(loc.Dotted.Loc.Variable) worked" },
}.ToDictionary(b => b.Id);

var localization = new Localization(0, null, "x-none", variables, new Dictionary<string, LocalizedControl>());

Expand All @@ -45,6 +48,10 @@ public void CanRecursivelyResolveVariables()
WixAssert.StringEqual("Welcome to Localized Product Name Enterprise Edition v1.2.3", result.Value);
Assert.True(result.UpdatedValue);

result = variableResolver.ResolveVariables(null, "start !(loc.NestedDotted.Loc.Variable) end");
WixAssert.StringEqual("start Dotted.Loc.Variable = Localized Product Name Enterprise Edition v1.2.3 worked end", result.Value);
Assert.True(result.UpdatedValue);

result = variableResolver.ResolveVariables(null, "Welcome to !(bind.property.ProductVersion)");
WixAssert.StringEqual("Welcome to !(bind.property.ProductVersion)", result.Value);
Assert.False(result.UpdatedValue);
Expand Down

0 comments on commit b1e207c

Please sign in to comment.