mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-11-21 23:32:19 +00:00
Backport pull request #17929 from jellyfin/release-12.z
Fix ContainsSubPath check
Original-merge: b55ea60da6
Merged-by: crobibero <cody@robibe.ro>
Backported-by: Cody Robibero <cody@robibe.ro>
This commit is contained in:
parent
f62f3cf9b0
commit
4e1c55031f
2 changed files with 45 additions and 3 deletions
|
|
@ -489,11 +489,18 @@ namespace Emby.Server.Implementations.IO
|
|||
ArgumentException.ThrowIfNullOrEmpty(parentPath);
|
||||
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||
|
||||
return path.Contains(
|
||||
Path.TrimEndingDirectorySeparator(parentPath) + Path.DirectorySeparatorChar,
|
||||
_isEnvironmentCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal);
|
||||
var parent = Path.TrimEndingDirectorySeparator(parentPath);
|
||||
|
||||
// The parent has to be an anchored prefix of the path, otherwise unrelated paths that merely
|
||||
// contain the parent as a segment (e.g. /media and /data/media/tv) would be treated as related.
|
||||
return path.Length > parent.Length
|
||||
&& path.StartsWith(parent, _isEnvironmentCaseInsensitive ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)
|
||||
&& (Path.EndsInDirectorySeparator(parent) || IsDirectorySeparator(path[parent.Length]));
|
||||
}
|
||||
|
||||
private static bool IsDirectorySeparator(char c)
|
||||
=> c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar;
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual bool AreEqual(string path1, string path2)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue