File tree Expand file tree Collapse file tree 3 files changed +46
-11
lines changed
src/React.AspNet.Middleware Expand file tree Collapse file tree 3 files changed +46
-11
lines changed Original file line number Diff line number Diff line change 1
- /*
1
+ /*
2
2
* Copyright (c) 2015, Facebook, Inc.
3
3
* All rights reserved.
4
4
*
5
5
* This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
7
* of patent rights can be found in the PATENTS file in the same directory.
8
8
*/
9
9
13
13
namespace React . AspNet
14
14
{
15
15
/// <summary>
16
- /// Handles file system functionality, such as reading files. Maps all paths from
16
+ /// Handles file system functionality, such as reading files. Maps all paths from
17
17
/// application-relative (~/...) to full paths using ASP.NET's MapPath method.
18
18
/// </summary>
19
19
public class AspNetFileSystem : FileSystemBase
@@ -36,12 +36,13 @@ public AspNetFileSystem(IHostingEnvironment hostingEnv)
36
36
/// <returns>Full path of the file</returns>
37
37
public override string MapPath ( string relativePath )
38
38
{
39
- if ( relativePath . StartsWith ( _hostingEnv . WebRootPath ) )
40
- {
41
- return relativePath ;
42
- }
43
- relativePath = relativePath . TrimStart ( '~' ) . TrimStart ( '/' ) ;
44
- return Path . Combine ( _hostingEnv . WebRootPath , relativePath ) ;
39
+ if ( relativePath . StartsWith ( _hostingEnv . WebRootPath ) )
40
+ {
41
+ return relativePath ;
42
+ }
43
+ relativePath = relativePath . TrimStart ( '~' ) . TrimStart ( '/' ) ;
44
+
45
+ return Path . GetFullPath ( Path . Combine ( _hostingEnv . WebRootPath , relativePath ) ) ;
45
46
}
46
47
}
47
48
}
Original file line number Diff line number Diff line change
1
+ #if NETCOREAPP2_0
2
+
3
+ using System . Runtime . InteropServices ;
4
+ using Microsoft . AspNetCore . Hosting ;
5
+ using Moq ;
6
+ using React . AspNet ;
7
+ using Xunit ;
8
+
9
+ namespace React . Tests . Core
10
+ {
11
+ public class MiddlewareTests
12
+ {
13
+ [ Fact ]
14
+ public void ForwardSlashesAreTransformed ( )
15
+ {
16
+ var environment = new Mock < IHostingEnvironment > ( ) ;
17
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
18
+ {
19
+ environment . Setup ( x => x . WebRootPath ) . Returns ( "c:\\ temp" ) ;
20
+ Assert . Equal ( "c:\\ temp\\ wwwroot\\ script.js" , new AspNetFileSystem ( environment . Object ) . MapPath ( "~/wwwroot/script.js" ) ) ;
21
+ }
22
+ else
23
+ {
24
+ environment . Setup ( x => x . WebRootPath ) . Returns ( "/var/www" ) ;
25
+ Assert . Equal ( "/var/www/wwwroot/script.js" , new AspNetFileSystem ( environment . Object ) . MapPath ( "~/wwwroot/script.js" ) ) ;
26
+ }
27
+ }
28
+ }
29
+ }
30
+ #endif
Original file line number Diff line number Diff line change 1
- <Project Sdk =" Microsoft.NET.Sdk" >
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
2
3
3
<PropertyGroup >
4
4
<Copyright >Copyright 2014-Present Facebook, Inc</Copyright >
30
30
<ProjectReference Include =" ..\..\src\React.Router\React.Router.csproj" />
31
31
</ItemGroup >
32
32
33
+ <ItemGroup Condition =" '$(TargetFramework)' == 'netcoreapp2.0' " >
34
+ <PackageReference Include =" Microsoft.AspNetCore.Hosting.Abstractions" Version =" 2.0.0" />
35
+ </ItemGroup >
36
+
33
37
<ItemGroup >
34
38
<PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 15.5.0" />
35
39
<PackageReference Include =" Moq" Version =" 4.8.3" />
36
40
<PackageReference Include =" xunit" Version =" 2.3.1" />
37
41
<PackageReference Include =" xunit.runner.visualstudio" Version =" 2.3.1" />
38
- <DotNetCliToolReference Include =" dotnet-xunit" Version =" 2.3.1" />
42
+ <DotNetCliToolReference Include =" dotnet-xunit" Version =" 2.3.1" />
39
43
</ItemGroup >
40
44
41
45
<ItemGroup Condition =" '$(TargetFramework)' == 'net452' " >
You can’t perform that action at this time.
0 commit comments