From 85647ba0c40862f3a4fdfe35f242e59737bb131e Mon Sep 17 00:00:00 2001 From: David Wengier Date: Thu, 7 May 2020 12:56:21 +1000 Subject: [PATCH] Prevent error when filenames have braces in them --- .../Services/PullRequestEditorService.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/GitHub.App/Services/PullRequestEditorService.cs b/src/GitHub.App/Services/PullRequestEditorService.cs index 9824f0f0ce..50bf091988 100644 --- a/src/GitHub.App/Services/PullRequestEditorService.cs +++ b/src/GitHub.App/Services/PullRequestEditorService.cs @@ -219,10 +219,10 @@ await pullRequestService.ExtractToTempFile( frame = VisualStudio.Services.DifferenceService.OpenComparisonWindow2( leftFile, rightFile, - caption, - tooltip, - leftLabel, - rightLabel, + SanitizeForDisplay(caption), + SanitizeForDisplay(tooltip), + SanitizeForDisplay(leftLabel), + SanitizeForDisplay(rightLabel), string.Empty, string.Empty, (uint)options); @@ -284,6 +284,13 @@ await pullRequestService.ExtractToTempFile( } } + private static string SanitizeForDisplay(string caption) + { + // The diff window passes captions and tooltips through string.Format, with {0} and {1} being the left and right file respectively, but we already + // nicely format the file names with extra info we know, so we have to escape braces to prevent unwanted formatting, or invalid format errors. + return caption.Replace("{", "{{").Replace("}", "}}"); + } + /// public Task OpenDiff( IPullRequestSession session,