Skip to content

Commit 139a778

Browse files
committed
Check newlines in conditions before replacing
1 parent f4bfa8e commit 139a778

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/System.Management.Automation/engine/CommandCompletion/CompletionHelpers.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,19 @@ internal static IEnumerable<CompletionResult> GetMatchingResults(
6262
/// <param name="wordToComplete">The word to complete.</param>
6363
/// <returns>The normalized word with escaped newlines replaced.</returns>
6464
internal static string NormalizeLineEndings(string wordToComplete)
65-
=> wordToComplete.Replace("\r", "`r").Replace("\n", "`n");
65+
{
66+
if (wordToComplete.Contains('\r'))
67+
{
68+
wordToComplete = wordToComplete.Replace("\r", "`r");
69+
}
70+
71+
if (wordToComplete.Contains('\n'))
72+
{
73+
wordToComplete = wordToComplete.Replace("\n", "`n");
74+
}
75+
76+
return wordToComplete;
77+
}
6678

6779
/// <summary>
6880
/// Defines a strategy for determining if a value matches a word or pattern.

0 commit comments

Comments
 (0)