File tree Expand file tree Collapse file tree 3 files changed +46
-10
lines changed
src/React.AspNet.Middleware Expand file tree Collapse file tree 3 files changed +46
-10
lines changed Original file line number Diff line number Diff line change 1- /*
1+ /*
22 * Copyright (c) 2015, Facebook, Inc.
33 * All rights reserved.
44 *
55 * 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
77 * of patent rights can be found in the PATENTS file in the same directory.
88 */
99
1313namespace React . AspNet
1414{
1515 /// <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
1717 /// application-relative (~/...) to full paths using ASP.NET's MapPath method.
1818 /// </summary>
1919 public class AspNetFileSystem : FileSystemBase
@@ -36,12 +36,13 @@ public AspNetFileSystem(IHostingEnvironment hostingEnv)
3636 /// <returns>Full path of the file</returns>
3737 public override string MapPath ( string relativePath )
3838 {
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 ) ) ;
4546 }
4647 }
4748}
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 2222 <ProjectReference Include =" ..\..\src\React.Web.Mvc4\React.Web.Mvc4.csproj" />
2323 </ItemGroup >
2424
25+
26+ <ItemGroup Condition =" '$(TargetFramework)' == 'netcoreapp2.0' " >
27+ <PackageReference Include =" Microsoft.AspNetCore.Hosting.Abstractions" Version =" 2.0.0" />
28+ </ItemGroup >
29+
2530 <ItemGroup >
2631 <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 15.5.0" />
2732 <PackageReference Include =" Moq" Version =" 4.5.30" />
2833 <PackageReference Include =" xunit" Version =" 2.3.1" />
2934 <PackageReference Include =" xunit.runner.visualstudio" Version =" 2.3.1" />
30- <DotNetCliToolReference Include =" dotnet-xunit" Version =" 2.3.1" />
35+ <DotNetCliToolReference Include =" dotnet-xunit" Version =" 2.3.1" />
3136 </ItemGroup >
3237
3338 <ItemGroup Condition =" '$(TargetFramework)' == 'net452' " >
You can’t perform that action at this time.
0 commit comments