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

Prevent error when filenames have braces in them #2512

Merged
merged 3 commits into from
Jun 9, 2020
Merged
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
15 changes: 11 additions & 4 deletions src/GitHub.App/Services/PullRequestEditorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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("}", "}}");
}

/// <inheritdoc/>
public Task<IDifferenceViewer> OpenDiff(
IPullRequestSession session,
Expand Down