Skip to content

[StaticWebAssets] Explicitly use invariant culture during parsing #49056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/9.0.3xx
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/StaticWebAssetsSdk/Tasks/Data/StaticWebAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ private static StaticWebAsset FromTaskItemCore(ITaskItem item) =>
CopyToPublishDirectory = item.GetMetadata(nameof(CopyToPublishDirectory)),
OriginalItemSpec = item.GetMetadata(nameof(OriginalItemSpec)),
FileLength = item.GetMetadata("FileLength") is string fileLengthString &&
long.TryParse(fileLengthString, out var fileLength) ? fileLength : -1,
long.TryParse(fileLengthString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var fileLength) ? fileLength : -1,
LastWriteTime = item.GetMetadata("LastWriteTime") is string lastWriteTimeString &&
DateTimeOffset.TryParse(lastWriteTimeString, out var lastWriteTime) ? lastWriteTime : DateTimeOffset.MinValue
DateTimeOffset.TryParseExact(lastWriteTimeString, DateTimeAssetFormat, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var lastWriteTime) ?
lastWriteTime :
DateTimeOffset.MinValue
};

public void ApplyDefaults()
Expand Down Expand Up @@ -485,6 +487,13 @@ public void Normalize()
BasePath = Normalize(BasePath);
RelativePath = Normalize(RelativePath, allowEmpyPath: true);
RelatedAsset = !string.IsNullOrEmpty(RelatedAsset) ? Path.GetFullPath(RelatedAsset) : RelatedAsset;

if (FileLength < 0 || LastWriteTime == DateTimeOffset.MinValue)
{
var file = ResolveFile(Identity, OriginalItemSpec);
FileLength = file.Length;
LastWriteTime = file.LastWriteTimeUtc;
}
}

// Normalizes the given path to a content root path in the way we expect it:
Expand Down