Skip to content

Commit

Permalink
[wasm][bcl] Handle correctly backslash in file name (mono#19488)
Browse files Browse the repository at this point in the history
* [wasm][bcl] Handle correctly backslash in file name

- Modify IO file to assign backslash to alternate directory separator by default
- Add tests for issue mono#18933

* [wasm][tests] Skip two tests for wasm

- After internal discussions decided to skip these two tests on wasm

   1. GetDirectories_Backslash
   1. GetFiles_Backslash

* [wasm][tests] PathIsRooted tests failing

- skip subtest #9 if WASM
- To fix issue mono#18933 we set the AltDirectorySeparatorChar as well.  This causes the `Assert.IsTrue (!Path.IsPathRooted ("\\"), "IsPathRooted #9");` to fail. Path.IsPathFullyQualified Method handles paths that use both the DirectorySeparatorChar and the AltDirectorySeparatorChar characters.

* [wasm][tests] PathIsRooted tests failing

- skip if WASM
  • Loading branch information
kjpou1 authored Apr 11, 2020
1 parent fc7ea0a commit 5a3e168
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mcs/class/corlib/Test/System.IO/DirectoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,7 @@ public void GetDirectories ()
}

[Test] // bug #346123
[Category ("NotWasm")]
public void GetDirectories_Backslash ()
{
if (!RunningOnUnix)
Expand Down Expand Up @@ -1567,6 +1568,7 @@ public void GetFiles ()
}

[Test] // bug #346123
[Category ("NotWasm")]
public void GetFiles_Backslash ()
{
if (!RunningOnUnix)
Expand Down
6 changes: 6 additions & 0 deletions mcs/class/corlib/Test/System.IO/PathTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,15 @@ public void IsPathRooted ()
Assert.IsTrue (Path.IsPathRooted ("\\"), "IsPathRooted #16");
Assert.IsTrue (Path.IsPathRooted ("\\\\"), "IsPathRooted #17");
} else {
// To fix issue https://github.com/mono/mono/issues/18933 we set the AltDirectorySeparatorChar as well.
// This causes the Assert.IsTrue (!Path.IsPathRooted ("\\"), "IsPathRooted #09"); to fail.
// Path.IsPathFullyQualified Method handles paths that use both the DirectorySeparatorChar
// and the AltDirectorySeparatorChar characters.
#if !WASM
Assert.IsTrue (!Path.IsPathRooted ("\\"), "IsPathRooted #09");
Assert.IsTrue (!Path.IsPathRooted ("\\\\"), "IsPathRooted #10");
Assert.IsTrue (!Path.IsPathRooted ("z:"), "IsPathRooted #11");
#endif
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions mono/metadata/w32file.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,14 @@ ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar (void)
gunichar2
ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar (void)
{
#if TARGET_WASM
return (gunichar2) '\\'; /* backslash issue https://github.com/mono/mono/issues/18933 */
#else
if (IS_PORTABILITY_SET)
return (gunichar2) '\\'; /* backslash */
else
return (gunichar2) '/'; /* forward slash */
#endif
}

gunichar2
Expand Down
19 changes: 19 additions & 0 deletions sdks/wasm/tests/browser/src/BrowserTestSuite/issues-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,24 @@ describe("The WebAssembly Issues Test Suite",function(){

}, DEFAULT_TIMEOUT);

it('https://github.com/mono/mono/issues/18933 System.IO.Path.GetFileName does not work - GetFileName.', () => {
//karmaHTML.issuesspec.document gives the access to the Document object of 'http-spec.html' file
var _document = karmaHTML.issuesspec.document;


var ret = _document.Module.BINDING.call_static_method("[IssuesTestSuite]TestSuite.Program:Issue18933_FileName_Backslash");
assert.equal(ret, "File1.txt", "result doesn't match File1.txt");

}, DEFAULT_TIMEOUT);

it('https://github.com/mono/mono/issues/18933 System.IO.Path.GetFileName does not work - DirectoryInfo.', () => {
//karmaHTML.issuesspec.document gives the access to the Document object of 'http-spec.html' file
var _document = karmaHTML.issuesspec.document;


var ret = _document.Module.BINDING.call_static_method("[IssuesTestSuite]TestSuite.Program:Issue18933_Directory_Backslash");
assert.equal(ret, "File1.txt", "result doesn't match File1.txt");

}, DEFAULT_TIMEOUT);

});
15 changes: 10 additions & 5 deletions sdks/wasm/tests/browser/src/IssuesTestSuite/IssuesTestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,21 @@ static HttpClient CreateHttpClient()
{
BaseApiUrl = (string)location.GetObjectProperty("origin");
}
// WasmHttpMessageHandler.StreamingEnabled = true;
// var client = new System.Net.Http.HttpClient()
// {
// DefaultRequestHeaders = { { "origin", "WindowsCalculator" } }
// };

return new HttpClient() { BaseAddress = new Uri(BaseApiUrl), DefaultRequestHeaders = { { "origin", "WindowsCalculator" } } };
}

// https://github.com/mono/mono/issues/18933 System.IO.Path.GetFileName doesn't work
public static string Issue18933_FileName_Backslash ()
{
return System.IO.Path.GetFileName(@"C:\FakePath\File1.txt");
}

// https://github.com/mono/mono/issues/18933 System.IO.Path.GetFileName doesn't work
public static string Issue18933_Directory_Backslash()
{
return new System.IO.DirectoryInfo(@"C:\FakePath\File1.txt").Name;
}
}

[Flags]
Expand Down

0 comments on commit 5a3e168

Please sign in to comment.