Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal static ScriptAnalysis Analyze(string path, ExecutionContext context)
// So eat the invalid operation
}

string scriptContent = ReadScript(path);
string scriptContent = File.ReadAllText(path, Encoding.Default);

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

internal static string ReadScript(string path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinGC94 Do you think it is good to remove the method? Won't this code be less readable?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's perfectly fine. If anything it's arguably easier to understand when it's just File.ReadAllText because you don't have to check if ReadScript does anything weird.

{
using (FileStream readerStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
Microsoft.Win32.SafeHandles.SafeFileHandle safeFileHandle = readerStream.SafeFileHandle;

using (StreamReader scriptReader = new StreamReader(readerStream, Encoding.Default))
{
return scriptReader.ReadToEnd();
}
}
}

internal List<string> DiscoveredExports { get; set; }

internal Dictionary<string, string> DiscoveredAliases { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/PsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ internal static Hashtable EvaluatePowerShellDataFile(

internal static Hashtable GetModuleManifestProperties(string psDataFilePath, string[] keys)
{
string dataFileContents = ScriptAnalysis.ReadScript(psDataFilePath);
string dataFileContents = File.ReadAllText(psDataFilePath, Encoding.Default);
ParseError[] parseErrors;
var ast = (new Parser()).Parse(psDataFilePath, dataFileContents, null, out parseErrors, ParseMode.ModuleAnalysis);
if (parseErrors.Length > 0)
Expand Down
Loading