Fix https://github.com/wixtoolset/issues/issues/5860 recursive loc strings.
Bob Arnson committed
Mar 11, 2020 at 20:54 UTC
61d0e33943811cc31aeeae0c8c1c5c5768986bbe
2 files changed
+41
-2
src/WixToolset.Core/VariableResolver.cs
+4
-2
@@ -35,7 +35,7 @@ namespace WixToolset.Core
35
36
private IMessaging Messaging { get; }
37
38
- public int VariableCount => this.wixVariables.Count;
38
+ public int VariableCount => this.wixVariables.Count;
39
40
public void AddLocalization(Localization localization)
41
{
@@ -94,7 +94,7 @@ namespace WixToolset.Core
94
result.IsDefault = true;
95
result.Value = value;
96
97
- if (0 < matches.Count)
97
+ while (!result.DelayedResolve && matches.Count > 0)
98
{
99
var sb = new StringBuilder(value);
100
@@ -203,6 +203,8 @@ namespace WixToolset.Core
203
}
204
205
result.Value = sb.ToString();
206
+ value = result.Value;
207
+ matches = Common.WixVariableRegex.Matches(value);
208
}
209
210
return result;
src/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs
new
+37
@@ -0,0 +1,37 @@
1
+
2
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
+
4
+namespace WixToolsetTest.CoreIntegration
5
+{
6
+ using System.Collections.Generic;
7
+ using WixToolset.Core;
8
+ using WixToolset.Data;
9
+ using WixToolset.Data.Bind;
10
+ using WixToolset.Extensibility.Services;
11
+ using Xunit;
12
+
13
+ public class VariableResolverFixture
14
+ {
15
+ [Fact]
16
+ public void CanRecursivelyResolveVariables()
17
+ {
18
+ var serviceProvider = new WixToolsetServiceProvider();
19
+ var variableResolver = serviceProvider.GetService<IVariableResolver>();
20
+
21
+ var variables = new Dictionary<string, BindVariable>()
22
+ {
23
+ { "ProductName", new BindVariable() { Id = "ProductName", Value = "Localized Product Name" } },
24
+ { "ProductNameEdition", new BindVariable() { Id = "ProductNameEdition", Value = "!(loc.ProductName) Enterprise Edition" } },
25
+ { "ProductNameEditionVersion", new BindVariable() { Id = "ProductNameEditionVersion", Value = "!(loc.ProductNameEdition) v1.2.3" } },
26
+ };
27
+
28
+ var localization = new Localization(0, "x-none", variables, new Dictionary<string,LocalizedControl>());
29
+
30
+ variableResolver.AddLocalization(localization);
31
+
32
+ Assert.Equal("Welcome to Localized Product Name", variableResolver.ResolveVariables(null, "Welcome to !(loc.ProductName)", false).Value);
33
+ Assert.Equal("Welcome to Localized Product Name Enterprise Edition", variableResolver.ResolveVariables(null, "Welcome to !(loc.ProductNameEdition)", false).Value);
34
+ Assert.Equal("Welcome to Localized Product Name Enterprise Edition v1.2.3", variableResolver.ResolveVariables(null, "Welcome to !(loc.ProductNameEditionVersion)", false).Value);
35
+ }
36
+ }
37
+}