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

Commit

Permalink
Merge pull request #2512 from davidwengier/FixDiffCaptions
Browse files Browse the repository at this point in the history
Prevent error when filenames have braces in them
  • Loading branch information
jcansdale authored Jun 9, 2020
2 parents c56f7f2 + a1dc901 commit bb629da
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit bb629da

Please sign in to comment.