aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Converters/WixConverter.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixToolset.Converters/WixConverter.cs76
1 files changed, 64 insertions, 12 deletions
diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs
index b8f2a516..1ef57fe7 100644
--- a/src/WixToolset.Converters/WixConverter.cs
+++ b/src/WixToolset.Converters/WixConverter.cs
@@ -179,6 +179,8 @@ namespace WixToolset.Converters
179 }; 179 };
180 180
181 private readonly Dictionary<XName, Action<XElement>> ConvertElementMapping; 181 private readonly Dictionary<XName, Action<XElement>> ConvertElementMapping;
182 private readonly Regex DeprecatedPrefixRegex = new Regex(@"(?<=(^|[^\$])(\$\$)*)\$(?=\(loc\.[^.].*\))",
183 RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
182 184
183 /// <summary> 185 /// <summary>
184 /// Instantiate a new Converter class. 186 /// Instantiate a new Converter class.
@@ -427,6 +429,13 @@ namespace WixToolset.Converters
427 { 429 {
428 if (node is XText text) 430 if (node is XText text)
429 { 431 {
432 if (null != text.Value)
433 {
434 if (this.TryFixDeprecatedLocalizationPrefixes(node, text.Value, out var newValue, ConverterTestType.DeprecatedLocalizationVariablePrefixInTextValue))
435 {
436 text.Value = newValue;
437 }
438 }
430 if (!String.IsNullOrWhiteSpace(text.Value)) 439 if (!String.IsNullOrWhiteSpace(text.Value))
431 { 440 {
432 text.Value = text.Value.Trim(); 441 text.Value = text.Value.Trim();
@@ -464,6 +473,20 @@ namespace WixToolset.Converters
464 } 473 }
465 } 474 }
466 475
476 private bool TryFixDeprecatedLocalizationPrefixes(XNode node, string value, out string newValue, ConverterTestType testType)
477 {
478 newValue = this.DeprecatedPrefixRegex.Replace(value, "!");
479
480 if (object.ReferenceEquals(newValue, value))
481 {
482 return false;
483 }
484
485 var message = testType == ConverterTestType.DeprecatedLocalizationVariablePrefixInTextValue ? "The prefix on the localization variable in the inner text is incorrect." : "The prefix on the localization variable in the attribute value is incorrect.";
486
487 return this.OnError(testType, node, message);
488 }
489
467 private void EnsurePrecedingWhitespaceCorrect(XText whitespace, XNode node, int level, ConverterTestType testType) 490 private void EnsurePrecedingWhitespaceCorrect(XText whitespace, XNode node, int level, ConverterTestType testType)
468 { 491 {
469 if (!WixConverter.LeadingWhitespaceValid(this.IndentationAmount, level, whitespace.Value)) 492 if (!WixConverter.LeadingWhitespaceValid(this.IndentationAmount, level, whitespace.Value))
@@ -492,25 +515,40 @@ namespace WixToolset.Converters
492 515
493 private void ConvertElement(XElement element) 516 private void ConvertElement(XElement element)
494 { 517 {
495 // Gather any deprecated namespaces, then update this element tree based on those deprecations.
496 var deprecatedToUpdatedNamespaces = new Dictionary<XNamespace, XNamespace>(); 518 var deprecatedToUpdatedNamespaces = new Dictionary<XNamespace, XNamespace>();
497 519
498 foreach (var declaration in element.Attributes().Where(a => a.IsNamespaceDeclaration)) 520 foreach (var attribute in element.Attributes())
499 { 521 {
500 if (element.Name == Wix3ElementName || element.Name == Include3ElementName) 522 if (attribute.IsNamespaceDeclaration)
501 {
502 this.SourceVersion = 3;
503 }
504 else if (element.Name == Wix4ElementName || element.Name == Include4ElementName)
505 { 523 {
506 this.SourceVersion = 4; 524 // Gather any deprecated namespaces, then update this element tree based on those deprecations.
507 } 525 var declaration = attribute;
508 526
509 if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns)) 527 if (element.Name == Wix3ElementName || element.Name == Include3ElementName)
528 {
529 this.SourceVersion = 3;
530 }
531 else if (element.Name == Wix4ElementName || element.Name == Include4ElementName)
532 {
533 this.SourceVersion = 4;
534 }
535
536 if (WixConverter.OldToNewNamespaceMapping.TryGetValue(declaration.Value, out var ns))
537 {
538 if (this.OnError(ConverterTestType.XmlnsValueWrong, declaration, "The namespace '{0}' is out of date. It must be '{1}'.", declaration.Value, ns.NamespaceName))
539 {
540 deprecatedToUpdatedNamespaces.Add(declaration.Value, ns);
541 }
542 }
543 }
544 else
510 { 545 {
511 if (this.OnError(ConverterTestType.XmlnsValueWrong, declaration, "The namespace '{0}' is out of date. It must be '{1}'.", declaration.Value, ns.NamespaceName)) 546 if (null != attribute.Value)
512 { 547 {
513 deprecatedToUpdatedNamespaces.Add(declaration.Value, ns); 548 if (this.TryFixDeprecatedLocalizationPrefixes(element, attribute.Value, out var newValue, ConverterTestType.DeprecatedLocalizationVariablePrefixInAttributeValue))
549 {
550 attribute.Value = newValue;
551 }
514 } 552 }
515 } 553 }
516 } 554 }
@@ -1958,11 +1996,15 @@ namespace WixToolset.Converters
1958 /// </summary> 1996 /// </summary>
1959 WhitespacePrecedingEndElementWrong, 1997 WhitespacePrecedingEndElementWrong,
1960 1998
1999 // Before this point, ignore errors on convert operation
2000
1961 /// <summary> 2001 /// <summary>
1962 /// Displayed when the XML declaration is present in the source file. 2002 /// Displayed when the XML declaration is present in the source file.
1963 /// </summary> 2003 /// </summary>
1964 DeclarationPresent, 2004 DeclarationPresent,
1965 2005
2006 // After this point, ignore errors on format operation
2007
1966 /// <summary> 2008 /// <summary>
1967 /// Displayed when the xmlns attribute is missing from the document element. 2009 /// Displayed when the xmlns attribute is missing from the document element.
1968 /// </summary> 2010 /// </summary>
@@ -1974,6 +2016,16 @@ namespace WixToolset.Converters
1974 XmlnsValueWrong, 2016 XmlnsValueWrong,
1975 2017
1976 /// <summary> 2018 /// <summary>
2019 /// Displayed when inner text contains a deprecated $(loc.xxx) reference.
2020 /// </summary>
2021 DeprecatedLocalizationVariablePrefixInTextValue,
2022
2023 /// <summary>
2024 /// Displayed when an attribute value contains a deprecated $(loc.xxx) reference.
2025 /// </summary>
2026 DeprecatedLocalizationVariablePrefixInAttributeValue,
2027
2028 /// <summary>
1977 /// Assign an identifier to a File element when on Id attribute is specified. 2029 /// Assign an identifier to a File element when on Id attribute is specified.
1978 /// </summary> 2030 /// </summary>
1979 AssignAnonymousFileId, 2031 AssignAnonymousFileId,