Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit bb629da

Browse files
authored
Merge pull request #2512 from davidwengier/FixDiffCaptions
Prevent error when filenames have braces in them
2 parents c56f7f2 + a1dc901 commit bb629da

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/GitHub.App/Services/PullRequestEditorService.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ await pullRequestService.ExtractToTempFile(
219219
frame = VisualStudio.Services.DifferenceService.OpenComparisonWindow2(
220220
leftFile,
221221
rightFile,
222-
caption,
223-
tooltip,
224-
leftLabel,
225-
rightLabel,
222+
SanitizeForDisplay(caption),
223+
SanitizeForDisplay(tooltip),
224+
SanitizeForDisplay(leftLabel),
225+
SanitizeForDisplay(rightLabel),
226226
string.Empty,
227227
string.Empty,
228228
(uint)options);
@@ -284,6 +284,13 @@ await pullRequestService.ExtractToTempFile(
284284
}
285285
}
286286

287+
private static string SanitizeForDisplay(string caption)
288+
{
289+
// The diff window passes captions and tooltips through string.Format, with {0} and {1} being the left and right file respectively, but we already
290+
// nicely format the file names with extra info we know, so we have to escape braces to prevent unwanted formatting, or invalid format errors.
291+
return caption.Replace("{", "{{").Replace("}", "}}");
292+
}
293+
287294
/// <inheritdoc/>
288295
public Task<IDifferenceViewer> OpenDiff(
289296
IPullRequestSession session,

0 commit comments

Comments
 (0)