Skip to content

Commit b77c80e

Browse files
Replace custom method with File.ReadAllText() in ScriptAnalysis.cs (PowerShell#26060)
1 parent 47e38be commit b77c80e

2 files changed

Lines changed: 2 additions & 15 deletions

File tree

src/System.Management.Automation/engine/Modules/ScriptAnalysis.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal static ScriptAnalysis Analyze(string path, ExecutionContext context)
4040
// So eat the invalid operation
4141
}
4242

43-
string scriptContent = ReadScript(path);
43+
string scriptContent = File.ReadAllText(path, Encoding.Default);
4444

4545
ParseError[] errors;
4646
var moduleAst = (new Parser()).Parse(path, scriptContent, null, out errors, ParseMode.ModuleAnalysis);
@@ -89,19 +89,6 @@ internal static ScriptAnalysis Analyze(string path, ExecutionContext context)
8989
return result;
9090
}
9191

92-
internal static string ReadScript(string path)
93-
{
94-
using (FileStream readerStream = new FileStream(path, FileMode.Open, FileAccess.Read))
95-
{
96-
Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = readerStream.SafeFileHandle;
97-
98-
using (StreamReader scriptReader = new StreamReader(readerStream, Encoding.Default))
99-
{
100-
return scriptReader.ReadToEnd();
101-
}
102-
}
103-
}
104-
10592
internal List<string> DiscoveredExports { get; set; }
10693

10794
internal Dictionary<string, string> DiscoveredAliases { get; set; }

src/System.Management.Automation/utils/PsUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ internal static Hashtable EvaluatePowerShellDataFile(
340340

341341
internal static Hashtable GetModuleManifestProperties(string psDataFilePath, string[] keys)
342342
{
343-
string dataFileContents = ScriptAnalysis.ReadScript(psDataFilePath);
343+
string dataFileContents = File.ReadAllText(psDataFilePath, Encoding.Default);
344344
ParseError[] parseErrors;
345345
var ast = (new Parser()).Parse(psDataFilePath, dataFileContents, null, out parseErrors, ParseMode.ModuleAnalysis);
346346
if (parseErrors.Length > 0)

0 commit comments

Comments
 (0)