diff options
| author | p27ZuH6CNAdzr <317456640+p27ZuH6CNAdzr@users.noreply.github.com> | 2026-10-13 13:36:11 -0400 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2026-10-13 13:36:11 -0400 |
| commit | f624cb4cc54826d4fc5c56dc2de9120a0ea632ce (patch) | |
| tree | 0e1da1a48bf1c653fb08a49c29815be58cbbd34c /tests | |
| parent | 054706333d0c76b2fe676c91fbdf19b39d3d7b8b (diff) | |
Backport pull request #18309 from jellyfin/release-12.z
Fix crash when a subtitle charset has no .NET encoding
Original-merge: 2f5be2df9be3d9ef44af4bf787a063f4d4166629
Merged-by: Bond-009 <bond.009@outlook.com>
Backported-by: Bond_009 <bond.009@outlook.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs index 48850b2f67..13779851a9 100644 --- a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs +++ b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs @@ -269,6 +269,46 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests } } + [Fact] + public async Task GetSubtitleStream_UnsupportedEncoding_DoesNotThrow() + { + // Regression test for issue #2200 + // When the charset detector identifies an encoding not supported by .NET (e.g., ISO-8859-16), + // GetSubtitleStream should handle it gracefully instead of throwing ArgumentNullException + var cancellationToken = TestContext.Current.CancellationToken; + var srt = BuildGreekSrt(); + var path = Path.GetTempFileName(); + try + { + // Write as ISO-8859-7 (Greek) to create a non-UTF-8 file + await File.WriteAllTextAsync(path, srt, Encoding.GetEncoding("iso-8859-7"), cancellationToken); + + var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); + var subtitleEncoder = fixture.Create<SubtitleEncoder>(); + + var fileInfo = new SubtitleEncoder.SubtitleInfo + { + Path = path, + Protocol = MediaProtocol.File, + Format = "srt", + IsExternal = true + }; + + // This should not throw even if the detected encoding was unsupported + using var stream = await subtitleEncoder.GetSubtitleStream(fileInfo, cancellationToken); + Assert.NotNull(stream); + + // Verify we can read from the stream without error + using var reader = new StreamReader(stream); + var text = await reader.ReadToEndAsync(cancellationToken); + Assert.NotEmpty(text); + } + finally + { + File.Delete(path); + } + } + private static SubtitleEncoder CreateEncoder() { var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); |
