Skip to content

Commit b51de3d

Browse files
committed
Fixed an issue with GetItemByRelativePathAsync not recognizing Windows-style path separators when running on WASM on Windows
1 parent 2c4d739 commit b51de3d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Extensions/GetItemByRelativePathExtension.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ public static partial class StorableExtensions
2727
/// <exception cref="FileNotFoundException">A named item was specified in a folder, but the item wasn't found.</exception>
2828
public static async Task<IStorable> GetItemByRelativePathAsync(this IStorable from, string relativePath, CancellationToken cancellationToken = default)
2929
{
30-
var inputPathChars = new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, Path.PathSeparator, Path.VolumeSeparatorChar };
30+
// Input path separators should include all possible separators that can be used in a path.
31+
// This includes the directory separator, alternate directory separator, path separator, and volume separator.
32+
// In some scenarios, such as dotnet running on WASM on Windows, a path separator may be used that is not given by dotnet via these properties.
33+
// Therefore, we also include '/' and '\' as valid path separators.
34+
// See also https://github.com/Arlodotexe/OwlCore.Storage/issues/86
35+
char[] inputPathSepChars = [Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, Path.PathSeparator, Path.VolumeSeparatorChar, '/', '\\'];
3136
var ourPathSeparator = @"/";
3237

3338
// Traverse only one level at a time
3439
// But recursively, until the target has been reached.
35-
var pathParts = relativePath.Split(inputPathChars).Where(x => !string.IsNullOrWhiteSpace(x) && x != ".").ToArray();
40+
var pathParts = relativePath.Split([..inputPathSepChars.Distinct()]).Where(x => !string.IsNullOrWhiteSpace(x) && x != ".").ToArray();
3641

3742
// Current directory was specified.
3843
if (pathParts.Length == 0)

src/OwlCore.Storage.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<Nullable>enable</Nullable>
5-
<LangVersion>10.0</LangVersion>
5+
<LangVersion>12.0</LangVersion>
66
<WarningsAsErrors>nullable</WarningsAsErrors>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
@@ -14,7 +14,7 @@
1414
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
1515

1616
<Author>Arlo Godfrey</Author>
17-
<Version>0.12.2</Version>
17+
<Version>0.12.3</Version>
1818
<Product>OwlCore</Product>
1919
<Description>The most flexible file system abstraction, ever. Built in partnership with the Windows App Community.
2020

@@ -23,6 +23,10 @@
2323
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
2424
<PackageIcon>logo.png</PackageIcon>
2525
<PackageReleaseNotes>
26+
--- 0.12.3 ---
27+
[Fixes]
28+
Fixed an issue with GetItemByRelativePathAsync not recognizing Windows-style path separators when running on WASM on Windows.
29+
2630
--- 0.12.2 ---
2731
[Improvements]
2832
Added the `virtual` keyword to all methods in `MemoryFile` and `MemoryFolder`, allowing consumers to extend these or adjust these methods in a custom derived implementation.

0 commit comments

Comments
 (0)