Fix prompt string to be platform agnostic and keep its trailing spaces (#7255)
This commit is contained in:
parent
716ed2acbd
commit
f4a50eda0d
|
@ -479,6 +479,7 @@ namespace System.Management.Automation
|
|||
{
|
||||
prompt_str = code_str = string.Empty;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
string default_prompt_str = "PS > ";
|
||||
|
||||
int collectingPart = 1;
|
||||
foreach (char c in content)
|
||||
|
@ -495,7 +496,7 @@ namespace System.Management.Automation
|
|||
{
|
||||
if (collectingPart == 1)
|
||||
{
|
||||
prompt_str = "PS C:\\>";
|
||||
prompt_str = default_prompt_str;
|
||||
}
|
||||
code_str = builder.ToString().Trim();
|
||||
builder = new StringBuilder();
|
||||
|
@ -507,7 +508,7 @@ namespace System.Management.Automation
|
|||
|
||||
if (collectingPart == 1)
|
||||
{
|
||||
prompt_str = "PS C:\\>";
|
||||
prompt_str = default_prompt_str;
|
||||
code_str = builder.ToString().Trim();
|
||||
remarks_str = string.Empty;
|
||||
}
|
||||
|
|
|
@ -606,13 +606,14 @@ namespace System.Management.Automation
|
|||
|
||||
int paraNodes = GetParaMamlNodeCount(xmlNode.ChildNodes);
|
||||
int count = 0;
|
||||
|
||||
// Don't trim the content if this is an "introduction" node.
|
||||
bool trim = ! string.Equals(xmlNode.Name, "maml:introduction", StringComparison.OrdinalIgnoreCase);
|
||||
foreach (XmlNode childNode in xmlNode.ChildNodes)
|
||||
{
|
||||
if (childNode.LocalName.Equals("para", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
++count;
|
||||
PSObject paraPSObject = GetParaPSObject(childNode, count != paraNodes);
|
||||
PSObject paraPSObject = GetParaPSObject(childNode, count != paraNodes, trim: trim);
|
||||
if (paraPSObject != null)
|
||||
mshObjects.Add(paraPSObject);
|
||||
continue;
|
||||
|
@ -752,8 +753,9 @@ namespace System.Management.Automation
|
|||
/// </summary>
|
||||
/// <param name="xmlNode"></param>
|
||||
/// <param name="newLine"></param>
|
||||
/// <param name="trim"></param>
|
||||
/// <returns></returns>
|
||||
private static PSObject GetParaPSObject(XmlNode xmlNode, bool newLine)
|
||||
private static PSObject GetParaPSObject(XmlNode xmlNode, bool newLine, bool trim = true)
|
||||
{
|
||||
if (xmlNode == null)
|
||||
return null;
|
||||
|
@ -771,7 +773,12 @@ namespace System.Management.Automation
|
|||
}
|
||||
else
|
||||
{
|
||||
sb.Append(xmlNode.InnerText.Trim());
|
||||
var innerText = xmlNode.InnerText;
|
||||
if (trim)
|
||||
{
|
||||
innerText = innerText.Trim();
|
||||
}
|
||||
sb.Append(innerText);
|
||||
}
|
||||
|
||||
mshObject.Properties.Add(new PSNoteProperty("Text", sb.ToString()));
|
||||
|
|
|
@ -557,4 +557,18 @@ Describe 'get-help other tests' -Tags "CI" {
|
|||
It '$x.Parameters.parameter[1].defaultValue' { $x.Parameters.parameter[1].defaultValue | Should -BeExactly '42' }
|
||||
It '$x.Parameters.parameter[2].defaultValue' { $x.Parameters.parameter[2].defaultValue | Should -BeExactly 'parameter is mandatory' }
|
||||
}
|
||||
|
||||
Context 'get-help -Examples prompt string should have trailing space' {
|
||||
function foo {
|
||||
<#
|
||||
.EXAMPLE
|
||||
foo bar
|
||||
#>
|
||||
param()
|
||||
}
|
||||
|
||||
It 'prompt should be exactly "PS > " with trailing space' {
|
||||
(Get-Help foo -Examples).examples.example.introduction.Text | Should -BeExactly "PS > "
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue