internal static string GetFullPath(string fileSpec, string currentDirectory) { fileSpec = EscapingUtilities.UnescapeAll(fileSpec); string str = EscapingUtilities.Escape(NormalizePath(Path.Combine(currentDirectory, fileSpec))); if (EndsWithSlash(str)) { return(str); } Match match = FileUtilitiesRegex.DrivePattern.Match(fileSpec); Match match2 = FileUtilitiesRegex.UNCPattern.Match(str); if ((!match.Success || (match.Length != fileSpec.Length)) && (!match2.Success || (match2.Length != str.Length))) { return(str); } return(str + Path.DirectorySeparatorChar); }
/// <summary> /// Determines the full path for the given file-spec. /// ASSUMES INPUT IS STILL ESCAPED /// </summary> /// <param name="fileSpec">The file spec to get the full path of.</param> /// <param name="currentDirectory"></param> /// <returns>full path</returns> internal static string GetFullPath(string fileSpec, string currentDirectory) { // Sending data out of the engine into the filesystem, so time to unescape. fileSpec = FixFilePath(EscapingUtilities.UnescapeAll(fileSpec)); // Data coming back from the filesystem into the engine, so time to escape it back. string fullPath = EscapingUtilities.Escape(NormalizePath(Path.Combine(currentDirectory, fileSpec))); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !EndsWithSlash(fullPath)) { if (FileUtilitiesRegex.IsDrivePattern(fileSpec) || FileUtilitiesRegex.IsUncPattern(fullPath)) { // append trailing slash if Path.GetFullPath failed to (this happens with drive-specs and UNC shares) fullPath += Path.DirectorySeparatorChar; } } return(fullPath); }
/// <summary> /// Determines the full path for the given file-spec. /// ASSUMES INPUT IS STILL ESCAPED /// </summary> /// <param name="fileSpec">The file spec to get the full path of.</param> /// <param name="currentDirectory"></param> /// <returns>full path</returns> internal static string GetFullPath(string fileSpec, string currentDirectory) { // Sending data out of the engine into the filesystem, so time to unescape. fileSpec = FixFilePath(EscapingUtilities.UnescapeAll(fileSpec)); // Data coming back from the filesystem into the engine, so time to escape it back. string fullPath = EscapingUtilities.Escape(NormalizePath(Path.Combine(currentDirectory, fileSpec))); if (NativeMethodsShared.IsWindows && !EndsWithSlash(fullPath)) { Match drive = FileUtilitiesRegex.DrivePattern.Match(fileSpec); Match UNCShare = FileUtilitiesRegex.UNCPattern.Match(fullPath); if ((drive.Success && (drive.Length == fileSpec.Length)) || (UNCShare.Success && (UNCShare.Length == fullPath.Length))) { // append trailing slash if Path.GetFullPath failed to (this happens with drive-specs and UNC shares) fullPath += Path.DirectorySeparatorChar; } } return(fullPath); }