aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r--src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs8
-rw-r--r--src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs27
2 files changed, 30 insertions, 5 deletions
diff --git a/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs b/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs
index e4b6e959..7b20286c 100644
--- a/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs
+++ b/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs
@@ -15,10 +15,13 @@ namespace WixToolset.Core.ExtensibilityServices
15 public BackendHelper(IWixToolsetServiceProvider serviceProvider) 15 public BackendHelper(IWixToolsetServiceProvider serviceProvider)
16 { 16 {
17 this.Messaging = serviceProvider.GetService<IMessaging>(); 17 this.Messaging = serviceProvider.GetService<IMessaging>();
18 this.ParseHelper = serviceProvider.GetService<IParseHelper>();
18 } 19 }
19 20
20 private IMessaging Messaging { get; } 21 private IMessaging Messaging { get; }
21 22
23 private IParseHelper ParseHelper { get; }
24
22 public IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null) 25 public IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null)
23 { 26 {
24 var sourceFullPath = this.GetValidatedFullPath(sourceLineNumbers, source); 27 var sourceFullPath = this.GetValidatedFullPath(sourceLineNumbers, source);
@@ -49,6 +52,11 @@ namespace WixToolset.Core.ExtensibilityServices
49 }; 52 };
50 } 53 }
51 54
55 public string GetCanonicalRelativePath(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string relativePath)
56 {
57 return this.ParseHelper.GetCanonicalRelativePath(sourceLineNumbers, elementName, attributeName, relativePath);
58 }
59
52 public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null) 60 public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null)
53 { 61 {
54 return new TrackedFile(path, type, sourceLineNumbers); 62 return new TrackedFile(path, type, sourceLineNumbers);
diff --git a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
index af3f40aa..de5595e1 100644
--- a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
+++ b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
@@ -540,11 +540,7 @@ namespace WixToolset.Core.ExtensibilityServices
540 } 540 }
541 else if (allowRelative) 541 else if (allowRelative)
542 { 542 {
543 var normalizedPath = value.Replace('\\', '/'); 543 value = this.GetCanonicalRelativePath(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value);
544 if (normalizedPath.StartsWith("../", StringComparison.Ordinal) || normalizedPath.Contains("/../"))
545 {
546 this.Messaging.Write(ErrorMessages.PayloadMustBeRelativeToCache(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
547 }
548 } 544 }
549 else if (CompilerCore.IsAmbiguousFilename(value)) 545 else if (CompilerCore.IsAmbiguousFilename(value))
550 { 546 {
@@ -705,6 +701,27 @@ namespace WixToolset.Core.ExtensibilityServices
705 } 701 }
706 } 702 }
707 703
704 public string GetCanonicalRelativePath(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string relativePath)
705 {
706 const string root = @"C:\";
707 if (!Path.IsPathRooted(relativePath))
708 {
709 var normalizedPath = Path.GetFullPath(root + relativePath);
710 if (normalizedPath.StartsWith(root))
711 {
712 var canonicalizedPath = normalizedPath.Substring(root.Length);
713 if (canonicalizedPath != relativePath)
714 {
715 this.Messaging.Write(WarningMessages.PathCanonicalized(sourceLineNumbers, elementName, attributeName, relativePath, canonicalizedPath));
716 }
717 return canonicalizedPath;
718 }
719 }
720
721 this.Messaging.Write(ErrorMessages.PayloadMustBeRelativeToCache(sourceLineNumbers, elementName, attributeName, relativePath));
722 return relativePath;
723 }
724
708 public SourceLineNumber GetSourceLineNumbers(XElement element) 725 public SourceLineNumber GetSourceLineNumbers(XElement element)
709 { 726 {
710 return Preprocessor.GetSourceLineNumbers(element); 727 return Preprocessor.GetSourceLineNumbers(element);