From 6b21265e139513c1a242d8677b154fcc0e1dc7ef Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 17 Jul 2020 15:22:14 -0700 Subject: Ensure named bindpaths are not found in unnamed bindpaths Fixes wixtoolset/issues#6200 --- src/WixToolset.Core/Bind/FileResolver.cs | 62 +++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'src/WixToolset.Core/Bind/FileResolver.cs') diff --git a/src/WixToolset.Core/Bind/FileResolver.cs b/src/WixToolset.Core/Bind/FileResolver.cs index d11fcadc..ba71c6c9 100644 --- a/src/WixToolset.Core/Bind/FileResolver.cs +++ b/src/WixToolset.Core/Bind/FileResolver.cs @@ -115,13 +115,14 @@ namespace WixToolset.Core.Bind } else // not a rooted path so let's try applying all the different source resolution options. { - string bindName = null; + var bindName = String.Empty; var path = source; - string pathWithoutSourceDir = null; + var pathWithoutSourceDir = String.Empty; if (source.StartsWith(BindPathOpenString, StringComparison.Ordinal)) { - int closeParen = source.IndexOf(')', BindPathOpenString.Length); + var closeParen = source.IndexOf(')', BindPathOpenString.Length); + if (-1 != closeParen) { bindName = source.Substring(BindPathOpenString.Length, closeParen - BindPathOpenString.Length); @@ -138,43 +139,48 @@ namespace WixToolset.Core.Bind foreach (var bindPath in bindPaths) { - if (!String.IsNullOrEmpty(bindName) && !String.IsNullOrEmpty(bindPath.Name)) + if (String.IsNullOrEmpty(bindName)) { - if (String.Equals(bindName, bindPath.Name, StringComparison.OrdinalIgnoreCase) && String.IsNullOrEmpty(resolved)) + if (String.IsNullOrEmpty(bindPath.Name)) { - var filePath = Path.Combine(bindPath.Path, path); - - checkedPaths.Add(filePath); - if (CheckFileExists(filePath)) + if (!String.IsNullOrEmpty(pathWithoutSourceDir)) { - resolved = filePath; + var filePath = Path.Combine(bindPath.Path, pathWithoutSourceDir); + + checkedPaths.Add(filePath); + if (CheckFileExists(filePath)) + { + resolved = filePath; + } } - } - } - else - { - if (!String.IsNullOrEmpty(pathWithoutSourceDir)) - { - var filePath = Path.Combine(bindPath.Path, pathWithoutSourceDir); - checkedPaths.Add(filePath); - if (CheckFileExists(filePath)) + if (String.IsNullOrEmpty(resolved)) { - resolved = filePath; + var filePath = Path.Combine(bindPath.Path, path); + + checkedPaths.Add(filePath); + if (CheckFileExists(filePath)) + { + resolved = filePath; + } } } + } + else if (bindName.Equals(bindPath.Name, StringComparison.OrdinalIgnoreCase)) + { + var filePath = Path.Combine(bindPath.Path, path); - if (String.IsNullOrEmpty(resolved)) + checkedPaths.Add(filePath); + if (CheckFileExists(filePath)) { - var filePath = Path.Combine(bindPath.Path, path); - - checkedPaths.Add(filePath); - if (CheckFileExists(filePath)) - { - resolved = filePath; - } + resolved = filePath; } } + + if (!String.IsNullOrEmpty(resolved)) + { + break; + } } } -- cgit v1.2.3-55-g6feb