mirror of
https://github.com/VSadov/Satori.git
synced 2025-06-10 01:50:53 +09:00
Use GetFullPath for normalization on relative files (#101083)
This commit is contained in:
parent
ccc74f342f
commit
9d88225f1e
2 changed files with 53 additions and 2 deletions
|
@ -51,13 +51,14 @@ namespace Microsoft.Extensions.FileSystemGlobbing
|
|||
// normalize
|
||||
foreach (string file in files)
|
||||
{
|
||||
string fileWithNormalSeparators = file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
|
||||
if (Path.IsPathRooted(file))
|
||||
{
|
||||
fileList.Add(Path.GetFullPath(file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)));
|
||||
fileList.Add(Path.GetFullPath(fileWithNormalSeparators));
|
||||
}
|
||||
else
|
||||
{
|
||||
fileList.Add(Path.Combine(normalizedRoot, file.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)));
|
||||
fileList.Add(Path.GetFullPath(Path.Combine(normalizedRoot, fileWithNormalSeparators)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.XUnitExtensions;
|
||||
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
|
||||
using Microsoft.Extensions.FileSystemGlobbing.Tests.TestUtility;
|
||||
using Xunit;
|
||||
|
@ -851,5 +852,54 @@ namespace Microsoft.Extensions.FileSystemGlobbing.Tests
|
|||
|
||||
Assert.Equal(1, fileSystemInfos.Count());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("./sdk/9.0.100-preview.4.24207.1/.version")]
|
||||
[InlineData("././sdk/9.0.100-preview.4.24207.1/.version")]
|
||||
public void VerifyFiles_RedundantSegment_HasMatches(string file)
|
||||
{
|
||||
foreach (string pattern in new[] { "**/*", "./", file })
|
||||
{
|
||||
var matcher = new Matcher();
|
||||
matcher.AddInclude(pattern);
|
||||
Assert.True(matcher.Match(file).HasMatches);
|
||||
Assert.True(matcher.Match([file]).HasMatches);
|
||||
Assert.True(matcher.Match("X:/foo", file).HasMatches);
|
||||
Assert.True(matcher.Match("X:/foo", [file]).HasMatches);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
public void VerifyFiles_ParentRedundantSegment_HasMatches()
|
||||
{
|
||||
string file = "sdk/9.0.100-preview.4.24207.1/.version";
|
||||
foreach (string pattern in new[] { "**/*", "./", file })
|
||||
{
|
||||
var matcher = new Matcher();
|
||||
matcher.AddInclude(pattern);
|
||||
Assert.True(matcher.Match("X:/foo", $"../foo/{file}").HasMatches);
|
||||
Assert.True(matcher.Match("X:/foo", [$"../foo/{file}"]).HasMatches);
|
||||
}
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
public void VerifyFiles_ParentRedundantSegment_CurrentDirectory_HasMatches()
|
||||
{
|
||||
string cwd = Environment.CurrentDirectory;
|
||||
string cwdFolderName = new DirectoryInfo(cwd).Name;
|
||||
if (cwd == cwdFolderName) // cwd is root, we can't do ../C:/
|
||||
{
|
||||
throw new SkipTestException($"CurrentDirectory {cwd} is the root directory.");
|
||||
}
|
||||
|
||||
string file = "sdk/9.0.100-preview.4.24207.1/.version";
|
||||
foreach (string pattern in new[] { "**/*", "./", file })
|
||||
{
|
||||
var matcher = new Matcher();
|
||||
matcher.AddInclude(pattern);
|
||||
Assert.True(matcher.Match($"../{cwdFolderName}/{file}").HasMatches);
|
||||
Assert.True(matcher.Match([$"../{cwdFolderName}/{file}"]).HasMatches);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue