Require delimiter immediately after filename match

This commit is contained in:
Joe Rogers 2022-02-21 22:08:54 +01:00
parent 15053516f8
commit cf033b25f8
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4
2 changed files with 11 additions and 3 deletions

View File

@ -43,6 +43,11 @@ namespace MediaBrowser.Providers.MediaInfo
/// </summary>
private readonly IMediaEncoder _mediaEncoder;
/// <summary>
/// The <see cref="NamingOptions"/> instance.
/// </summary>
private readonly NamingOptions _namingOptions;
/// <summary>
/// The <see cref="DlnaProfileType"/> of the files this resolver should resolve.
/// </summary>
@ -62,6 +67,7 @@ namespace MediaBrowser.Providers.MediaInfo
DlnaProfileType type)
{
_mediaEncoder = mediaEncoder;
_namingOptions = namingOptions;
_type = type;
_externalPathParser = new ExternalPathParser(namingOptions, localizationManager, _type);
}
@ -159,9 +165,11 @@ namespace MediaBrowser.Providers.MediaInfo
foreach (var file in files)
{
if (_compareInfo.IsPrefix(Path.GetFileNameWithoutExtension(file), video.FileNameWithoutExtension, CompareOptions, out int matchLength))
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
if (_compareInfo.IsPrefix(fileNameWithoutExtension, video.FileNameWithoutExtension, CompareOptions, out int matchLength)
&& (fileNameWithoutExtension.Length == matchLength || _namingOptions.MediaFlagDelimiters.Contains(fileNameWithoutExtension[matchLength].ToString())))
{
var externalPathInfo = _externalPathParser.ParseFile(file, Path.GetFileNameWithoutExtension(file)[matchLength..]);
var externalPathInfo = _externalPathParser.ParseFile(file, fileNameWithoutExtension[matchLength..]);
if (externalPathInfo != null)
{

View File

@ -113,7 +113,7 @@ public class MediaInfoResolverTests
[InlineData("My.Video.mp3")]
[InlineData("My.Video.png")]
[InlineData("My.Video.txt")]
// [InlineData("My.Video Sequel.srt")]
[InlineData("My.Video Sequel.srt")]
[InlineData("Some.Other.Video.srt")]
public void GetExternalFiles_FuzzyMatching_RejectsNonMatches(string file)
{