mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-06 06:12:52 +01:00
Use InvariantCulture when parsing machine-generated dates
DateTime.TryParse without an IFormatProvider falls back to the current thread culture, so the same string can parse differently (or fail) depending on the server's locale. None of these call sites deal with user-entered text - they parse dates that come from filenames, an HTTP header, ffprobe metadata and values the app itself wrote to the auth database - so InvariantCulture is the correct provider everywhere here. Fixes the S6580 / CA1305 warnings on these call sites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -125,7 +125,7 @@ namespace Emby.Naming.TV
|
|||||||
result.Success = true;
|
result.Success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (DateTime.TryParse(match.Groups[0].ValueSpan, out date))
|
else if (DateTime.TryParse(match.Groups[0].ValueSpan, CultureInfo.InvariantCulture, out date))
|
||||||
{
|
{
|
||||||
result.Year = date.Year;
|
result.Year = date.Year;
|
||||||
result.Month = date.Month;
|
result.Month = date.Month;
|
||||||
|
|||||||
@@ -2049,7 +2049,7 @@ public class ImageController : BaseJellyfinApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check If-Modified-Since header for time-based validation
|
// Check If-Modified-Since header for time-based validation
|
||||||
if (DateTime.TryParse(Request.Headers[HeaderNames.IfModifiedSince], out var ifModifiedSinceHeader))
|
if (DateTime.TryParse(Request.Headers[HeaderNames.IfModifiedSince], CultureInfo.InvariantCulture, out var ifModifiedSinceHeader))
|
||||||
{
|
{
|
||||||
// Return 304 if the image has not been modified since the client's cached version
|
// Return 304 if the image has not been modified since the client's cached version
|
||||||
if (dateImageModified <= ifModifiedSinceHeader)
|
if (dateImageModified <= ifModifiedSinceHeader)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Emby.Server.Implementations.Data;
|
using Emby.Server.Implementations.Data;
|
||||||
using Jellyfin.Database.Implementations;
|
using Jellyfin.Database.Implementations;
|
||||||
@@ -79,9 +80,9 @@ namespace Jellyfin.Server.Migrations.Routines
|
|||||||
foreach (var row in authenticatedDevices)
|
foreach (var row in authenticatedDevices)
|
||||||
{
|
{
|
||||||
var dateCreatedStr = row.GetString(9);
|
var dateCreatedStr = row.GetString(9);
|
||||||
_ = DateTime.TryParse(dateCreatedStr, out var dateCreated);
|
_ = DateTime.TryParse(dateCreatedStr, CultureInfo.InvariantCulture, out var dateCreated);
|
||||||
var dateLastActivityStr = row.GetString(10);
|
var dateLastActivityStr = row.GetString(10);
|
||||||
_ = DateTime.TryParse(dateLastActivityStr, out var dateLastActivity);
|
_ = DateTime.TryParse(dateLastActivityStr, CultureInfo.InvariantCulture, out var dateLastActivity);
|
||||||
|
|
||||||
if (row.IsDBNull(6))
|
if (row.IsDBNull(6))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1641,7 +1641,7 @@ namespace MediaBrowser.MediaEncoding.Probing
|
|||||||
|
|
||||||
// Credit to MCEBuddy: https://mcebuddy2x.codeplex.com/
|
// Credit to MCEBuddy: https://mcebuddy2x.codeplex.com/
|
||||||
// DateTime is reported along with timezone info (typically Z i.e. UTC hence assume None)
|
// DateTime is reported along with timezone info (typically Z i.e. UTC hence assume None)
|
||||||
if (tags.TryGetValue("WM/MediaOriginalBroadcastDateTime", out var premiereDateString) && DateTime.TryParse(year, null, DateTimeStyles.AdjustToUniversal, out var parsedDate))
|
if (tags.TryGetValue("WM/MediaOriginalBroadcastDateTime", out var premiereDateString) && DateTime.TryParse(year, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var parsedDate))
|
||||||
{
|
{
|
||||||
video.PremiereDate = parsedDate;
|
video.PremiereDate = parsedDate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ namespace MediaBrowser.Providers.Books.OpenPackagingFormat
|
|||||||
|
|
||||||
ReadStringInto("//dc:date", date =>
|
ReadStringInto("//dc:date", date =>
|
||||||
{
|
{
|
||||||
if (DateTime.TryParse(date, out var dateValue))
|
if (DateTime.TryParse(date, CultureInfo.InvariantCulture, out var dateValue))
|
||||||
{
|
{
|
||||||
book.PremiereDate = dateValue.Date;
|
book.PremiereDate = dateValue.Date;
|
||||||
book.ProductionYear = dateValue.Date.Year;
|
book.ProductionYear = dateValue.Date.Year;
|
||||||
|
|||||||
Reference in New Issue
Block a user