diff options
Diffstat (limited to '')
-rw-r--r-- | src/WixToolset.Core/VariableResolver.cs | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/WixToolset.Core/VariableResolver.cs b/src/WixToolset.Core/VariableResolver.cs index 4a65bec2..b1a5defc 100644 --- a/src/WixToolset.Core/VariableResolver.cs +++ b/src/WixToolset.Core/VariableResolver.cs | |||
@@ -66,9 +66,9 @@ namespace WixToolset.Core | |||
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | public IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly) | 69 | public IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value) |
70 | { | 70 | { |
71 | return this.ResolveVariables(sourceLineNumbers, value, localizationOnly, true); | 71 | return this.ResolveVariables(sourceLineNumbers, value, errorOnUnknown: true); |
72 | } | 72 | } |
73 | 73 | ||
74 | public bool TryGetLocalizedControl(string dialog, string control, out LocalizedControl localizedControl) | 74 | public bool TryGetLocalizedControl(string dialog, string control, out LocalizedControl localizedControl) |
@@ -82,25 +82,27 @@ namespace WixToolset.Core | |||
82 | /// </summary> | 82 | /// </summary> |
83 | /// <param name="sourceLineNumbers">The source line information for the value.</param> | 83 | /// <param name="sourceLineNumbers">The source line information for the value.</param> |
84 | /// <param name="value">The value to resolve.</param> | 84 | /// <param name="value">The value to resolve.</param> |
85 | /// <param name="localizationOnly">true to only resolve localization variables; false otherwise.</param> | ||
86 | /// <param name="errorOnUnknown">true if unknown variables should throw errors.</param> | 85 | /// <param name="errorOnUnknown">true if unknown variables should throw errors.</param> |
87 | /// <returns>The resolved value.</returns> | 86 | /// <returns>The resolved value.</returns> |
88 | internal IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool localizationOnly, bool errorOnUnknown) | 87 | internal IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool errorOnUnknown) |
89 | { | 88 | { |
90 | var matches = Common.WixVariableRegex.Matches(value); | 89 | var matches = Common.WixVariableRegex.Matches(value); |
91 | 90 | ||
92 | // the value is the default unless its substituted further down | 91 | // the value is the default unless it's substituted further down |
93 | var result = this.ServiceProvider.GetService<IVariableResolution>(); | 92 | var result = this.ServiceProvider.GetService<IVariableResolution>(); |
94 | result.IsDefault = true; | 93 | result.IsDefault = true; |
95 | result.Value = value; | 94 | result.Value = value; |
96 | 95 | ||
97 | while (!this.Messaging.EncounteredError && !result.DelayedResolve && matches.Count > 0) | 96 | var finalizeEscapes = false; |
97 | |||
98 | while (matches.Count > 0) | ||
98 | { | 99 | { |
100 | var updatedResultThisPass = false; | ||
99 | var sb = new StringBuilder(value); | 101 | var sb = new StringBuilder(value); |
100 | 102 | ||
101 | // notice how this code walks backward through the list | 103 | // notice how this code walks backward through the list |
102 | // because it modifies the string as we move through it | 104 | // because it modifies the string as we move through it |
103 | for (int i = matches.Count - 1; 0 <= i; i--) | 105 | for (var i = matches.Count - 1; 0 <= i; i--) |
104 | { | 106 | { |
105 | var variableNamespace = matches[i].Groups["namespace"].Value; | 107 | var variableNamespace = matches[i].Groups["namespace"].Value; |
106 | var variableId = matches[i].Groups["fullname"].Value; | 108 | var variableId = matches[i].Groups["fullname"].Value; |
@@ -130,12 +132,16 @@ namespace WixToolset.Core | |||
130 | // check for an escape sequence of !! indicating the match is not a variable expression | 132 | // check for an escape sequence of !! indicating the match is not a variable expression |
131 | if (0 < matches[i].Index && '!' == sb[matches[i].Index - 1]) | 133 | if (0 < matches[i].Index && '!' == sb[matches[i].Index - 1]) |
132 | { | 134 | { |
133 | if (!localizationOnly) | 135 | if (finalizeEscapes) |
134 | { | 136 | { |
135 | sb.Remove(matches[i].Index - 1, 1); | 137 | sb.Remove(matches[i].Index - 1, 1); |
136 | 138 | ||
137 | result.UpdatedValue = true; | 139 | result.UpdatedValue = true; |
138 | } | 140 | } |
141 | else | ||
142 | { | ||
143 | continue; | ||
144 | } | ||
139 | } | 145 | } |
140 | else | 146 | else |
141 | { | 147 | { |
@@ -154,7 +160,7 @@ namespace WixToolset.Core | |||
154 | resolvedValue = bindVariable.Value; | 160 | resolvedValue = bindVariable.Value; |
155 | } | 161 | } |
156 | } | 162 | } |
157 | else if (!localizationOnly && "wix" == variableNamespace) | 163 | else if ("wix" == variableNamespace) |
158 | { | 164 | { |
159 | // illegal syntax of $(wix.var) | 165 | // illegal syntax of $(wix.var) |
160 | if ('$' == sb[matches[i].Index]) | 166 | if ('$' == sb[matches[i].Index]) |
@@ -189,12 +195,13 @@ namespace WixToolset.Core | |||
189 | sb.Insert(matches[i].Index, resolvedValue); | 195 | sb.Insert(matches[i].Index, resolvedValue); |
190 | 196 | ||
191 | result.UpdatedValue = true; | 197 | result.UpdatedValue = true; |
198 | updatedResultThisPass = true; | ||
192 | } | 199 | } |
193 | else if ("loc" == variableNamespace && errorOnUnknown) // unresolved loc variable | 200 | else if ("loc" == variableNamespace && errorOnUnknown) // unresolved loc variable |
194 | { | 201 | { |
195 | this.Messaging.Write(ErrorMessages.LocalizationVariableUnknown(sourceLineNumbers, variableId)); | 202 | this.Messaging.Write(ErrorMessages.LocalizationVariableUnknown(sourceLineNumbers, variableId)); |
196 | } | 203 | } |
197 | else if (!localizationOnly && "wix" == variableNamespace && errorOnUnknown) // unresolved wix variable | 204 | else if ("wix" == variableNamespace && errorOnUnknown) // unresolved wix variable |
198 | { | 205 | { |
199 | this.Messaging.Write(ErrorMessages.WixVariableUnknown(sourceLineNumbers, variableId)); | 206 | this.Messaging.Write(ErrorMessages.WixVariableUnknown(sourceLineNumbers, variableId)); |
200 | } | 207 | } |
@@ -204,7 +211,22 @@ namespace WixToolset.Core | |||
204 | 211 | ||
205 | result.Value = sb.ToString(); | 212 | result.Value = sb.ToString(); |
206 | value = result.Value; | 213 | value = result.Value; |
207 | matches = Common.WixVariableRegex.Matches(value); | 214 | |
215 | if (finalizeEscapes) | ||
216 | { | ||
217 | // escaped references have been un-escaped, so we're done | ||
218 | break; | ||
219 | } | ||
220 | else if (updatedResultThisPass) | ||
221 | { | ||
222 | // we substituted loc strings, so make another pass to see if that brought in more loc strings | ||
223 | matches = Common.WixVariableRegex.Matches(value); | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | // make one final pass to un-escape any escaped references | ||
228 | finalizeEscapes = true; | ||
229 | } | ||
208 | } | 230 | } |
209 | 231 | ||
210 | return result; | 232 | return result; |