From 28c8abfda013d6aa568fde8b26da65522748d376 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 1 Aug 2022 17:07:49 -0500 Subject: Downgrade error to warning when search refs a reserved prefix variable. The engine doesn't actually prevent external callers from setting variables that start with 'Wix'. --- .../Data/BundleVariableNameRule.cs | 33 ++++++++++++++++++++++ .../Services/IBundleValidator.cs | 26 +++++++++++++++-- .../Services/IParseHelper.cs | 3 +- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/api/wix/WixToolset.Extensibility/Data/BundleVariableNameRule.cs (limited to 'src/api') diff --git a/src/api/wix/WixToolset.Extensibility/Data/BundleVariableNameRule.cs b/src/api/wix/WixToolset.Extensibility/Data/BundleVariableNameRule.cs new file mode 100644 index 00000000..eb6f7543 --- /dev/null +++ b/src/api/wix/WixToolset.Extensibility/Data/BundleVariableNameRule.cs @@ -0,0 +1,33 @@ +// 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. + +namespace WixToolset.Extensibility.Data +{ + using System; + + /// + /// When validating a bundle variable name, which special restrictions to ignore. + /// + [Flags] + public enum BundleVariableNameRule + { + /// + /// Enforce all special restrictions. + /// + EnforceAllRestrictions = 0x0, + + /// + /// Allow names of built-in variables. + /// + CanBeBuiltIn = 0x1, + + /// + /// Allow names of well-known variables. + /// + CanBeWellKnown = 0x2, + + /// + /// Allow names that are not built-in and are not well-known and start with 'Wix'. + /// + CanHaveReservedPrefix = 0x4, + } +} diff --git a/src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs b/src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs index 43f65fc8..3753d16d 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs @@ -33,15 +33,35 @@ namespace WixToolset.Extensibility.Services bool ValidateBundleMsiPropertyName(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string propertyName); /// - /// Validates a Bundle variable name and displays an error for an illegal value. + /// Validates a Bundle variable name that is being used to declare a Variable in the bundle manifest and displays an error for an illegal value. /// /// /// /// /// - /// Whether to bypass checks for reserved values. /// Whether the name is valid. - bool ValidateBundleVariableName(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string variableName, bool allowBuiltIn); + bool ValidateBundleVariableNameDeclaration(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string variableName); + + /// + /// Validates a Bundle variable name that is being used to reference a Variable and displays an error for an illegal value. + /// + /// + /// + /// + /// + /// + /// Whether the name is valid. + bool ValidateBundleVariableNameValue(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string variableName, BundleVariableNameRule nameRule); + + /// + /// Validates a Bundle variable name that is being used to set its value and displays an error for an illegal value. + /// + /// + /// + /// + /// + /// Whether the name is valid. + bool ValidateBundleVariableNameTarget(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string variableName); /// /// Validates a bundle condition and displays an error for an illegal value. diff --git a/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs b/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs index a8246b9b..3a3c2ceb 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs @@ -246,8 +246,9 @@ namespace WixToolset.Extensibility.Services /// /// Source line information about the owner element. /// The attribute containing the value to get. + /// A rule for the contents of the value. If the contents do not follow the rule, an error is thrown. /// The attribute's value. - string GetAttributeBundleVariableNameValue(SourceLineNumber sourceLineNumbers, XAttribute attribute); + string GetAttributeBundleVariableNameValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, BundleVariableNameRule nameRule = BundleVariableNameRule.CanBeWellKnown | BundleVariableNameRule.CanHaveReservedPrefix); /// /// Get a guid attribute value and displays an error for an illegal guid value. -- cgit v1.2.3-55-g6feb