Skip to content

Commit

Permalink
[604] fix: workout title template not handling special characters cor…
Browse files Browse the repository at this point in the history
…rectly (#609)

* [604] fix: workout title template not handling special characters correctly

* bump version and release notes

* tweak tests
  • Loading branch information
philosowaffle authored Jan 13, 2024
1 parent 968a7f0 commit 3420165
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public static class Constants
public const string WebUIName = "p2g_webui";
public const string ClientUIName = "p2g_clientui";

public const string AppVersion = "4.1.0";
public const string AppVersion = "4.2.0-rc";
}
}
6 changes: 4 additions & 2 deletions src/Common/Helpers/WorkoutHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Common.Dto.Peloton;
using HandlebarsDotNet;
using System.IO;
using System.Web;

namespace Common.Helpers;

Expand All @@ -27,7 +28,7 @@ public static string GetTitle(Workout workout, Format settings)
var template = settings.WorkoutTitleTemplate;
if (string.IsNullOrWhiteSpace(template))
template = new Format().WorkoutTitleTemplate;

var compiledTemplate = Handlebars.Compile(settings.WorkoutTitleTemplate);
var title = compiledTemplate(templateData);

Expand All @@ -38,7 +39,8 @@ public static string GetTitle(Workout workout, Format settings)
cleanedTitle = cleanedTitle.Replace(c, InvalidCharacterReplacer);
}

return cleanedTitle;
var result = HttpUtility.HtmlDecode(cleanedTitle);
return result;
}

public static string GetUniqueTitle(Workout workout, Format settings)
Expand Down
19 changes: 19 additions & 0 deletions src/UnitTests/Common/Helpers/WorkoutHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ public string GetTitle_Should_ReplaceInvalidChars(string title, string instructo
return WorkoutHelper.GetTitle(workout, new Format());
}

[TestCase("My Title", "é", ExpectedResult = "My_Title_with_é")]
[TestCase("My Title", "ä", ExpectedResult = "My_Title_with_ä")]
public string GetTitle_Should_Handle_SpecialChars(string title, string instructor)
{
var workout = new Workout()
{
Ride = new Ride()
{
Title = title,
Instructor = new Instructor()
{
Name = instructor
}
}
};

return WorkoutHelper.GetTitle(workout, new Format());
}

[Test]
public void GetTitle_NullRide_ShouldReturn_RideId()
{
Expand Down
12 changes: 1 addition & 11 deletions vNextReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@

## Features

- [#564] [#591] Set a custom title on Workouts using templating
- [#559] Ability to exclude Outdoor Cycling workouts from sycning
- [#600] Annual Challenge page now let's you know how many minutes you will need per day/week in order to meet the goal by the end of the year (based on the remaining time left)

## Fixes

- [#581] Fix broken Documentation link in UI
- [#580] Console Client couldn't load configuration file correctly (introduced by #564)
- [#588] Fix Annual Challenge page still trying to load 2023
- [#578] Fix VO2 and TE not updating on Garmin Connect

## Docs

- [#521] Called out that `\` special character is not currently supported in passwords
- [#604] Fix workout title template not handling special characters correctly

## Docker Tags

Expand Down

0 comments on commit 3420165

Please sign in to comment.