55using System . Collections . Generic ;
66using System . Diagnostics ;
77using System . IO ;
8+ using Microsoft . AspNetCore . Razor . Utilities ;
89
910namespace Microsoft . AspNetCore . Razor . Language ;
1011
@@ -93,6 +94,23 @@ protected override string NormalizeAndEnsureValidPath(string path)
9394
9495 var normalizedPath = path . Replace ( '\\ ' , '/' ) ;
9596
97+ // On Windows, check to see if this is a rooted file path. If it is, just return it.
98+ // This covers the following cases:
99+ //
100+ // 1. It is rooted within the project root. That's valid and we would have checked
101+ // specifically for that case below.
102+ // 2. It is rooted outside of the project root. That's invalid, and we don't want to
103+ // concatenate it with the project root. That would potentially produce an invalid
104+ // Windows path like 'C:/project/C:/other-project/some-file.cshtml'.
105+ //
106+ // Note that returning a path that is rooted outside of the project root will cause
107+ // the GetItem(...) method to throw, but it could be overridden by a descendant file
108+ // system.
109+ if ( PlatformInformation . IsWindows && PathUtilities . IsPathFullyQualified ( path ) )
110+ {
111+ return normalizedPath ;
112+ }
113+
96114 // Check if the given path is an absolute path. It is absolute if...
97115 //
98116 // 1. It is a network share path and starts with a '//' (e.g. //server/some/network/folder) or...
@@ -103,14 +121,6 @@ protected override string NormalizeAndEnsureValidPath(string path)
103121 return normalizedPath ;
104122 }
105123
106- // This might be an absolute path rooted outside of the project root. In that case,
107- // we just return it. This will mean that the GetItem(...) method will throw above,
108- // but it could be overridden by a descendant file system.
109- if ( PathUtilities . IsPathFullyQualified ( path ) )
110- {
111- return normalizedPath ;
112- }
113-
114124 // This is not an absolute path, so we combine it with Root to produce the final path.
115125
116126 // If the root doesn't end in a '/', and the path doesn't start with a '/', we'll need to add one.
0 commit comments