Skip to content

Commit e9f4af3

Browse files
Surayya Huseyn ZadaSurayya Huseyn Zada
authored andcommitted
address comments
1 parent 5094a41 commit e9f4af3

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/Containers/Microsoft.NET.Build.Containers/DigestUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal static string GetShaFromDigest(string digest)
2121
{
2222
if (!digest.StartsWith("sha256:", StringComparison.OrdinalIgnoreCase))
2323
{
24-
throw new ArgumentException("Invalid digest format. Digest must start with 'sha256:'.");
24+
throw new ArgumentException($"Invalid digest '{digest}'. Digest must start with 'sha256:'.");
2525
}
2626

2727
return digest.Substring("sha256:".Length);

src/Containers/Microsoft.NET.Build.Containers/ImageIndexGenerator.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static class ImageIndexGenerator
1313
/// <summary>
1414
/// Generates an image index from the given images.
1515
/// </summary>
16-
/// <param name="images"></param>
16+
/// <param name="images">Images to generate image index from.</param>
1717
/// <returns>Returns json string of image index and image index mediaType.</returns>
1818
/// <exception cref="ArgumentException"></exception>
1919
/// <exception cref="NotSupportedException"></exception>
@@ -45,6 +45,15 @@ internal static (string, string) GenerateImageIndex(BuiltImage[] images)
4545
}
4646
}
4747

48+
/// <summary>
49+
/// Generates an image index from the given images.
50+
/// </summary>
51+
/// <param name="images">Images to generate image index from.</param>
52+
/// <param name="manifestMediaType">Media type of the manifest.</param>
53+
/// <param name="imageIndexMediaType">Media type of the produced image index.</param>
54+
/// <returns>Returns json string of image index and image index mediaType.</returns>
55+
/// <exception cref="ArgumentException"></exception>
56+
/// <exception cref="NotSupportedException"></exception>
4857
internal static string GenerateImageIndex(BuiltImage[] images, string manifestMediaType, string imageIndexMediaType)
4958
{
5059
if (images.Length == 0)
@@ -116,6 +125,7 @@ private static string GetJsonStringFromImageIndex<T>(T imageIndex)
116125
{
117126
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
118127
};
128+
// To avoid things like \u002B for '+' especially in media types ("application/vnd.oci.image.manifest.v1\u002Bjson"), we use UnsafeRelaxedJsonEscaping.
119129
var escapeOptions = new JsonSerializerOptions
120130
{
121131
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping

src/Containers/Microsoft.NET.Build.Containers/LocalDaemons/ArchiveFileRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal async Task LoadAsync<T>(T image, SourceImageReference sourceReference,
2323
var directorySeparatorChar = Path.DirectorySeparatorChar;
2424

2525
// if doesn't end with a file extension, assume it's a directory
26-
if (!fullPath.Split(directorySeparatorChar).Last().Contains('.'))
26+
if (!Path.HasExtension(fullPath))
2727
{
2828
fullPath += Path.DirectorySeparatorChar;
2929
}

src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateImageIndex.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void Dispose()
2323
_cancellationTokenSource.Dispose();
2424
}
2525

26-
private bool IsLocalPull => string.IsNullOrEmpty(BaseRegistry.Trim());
26+
private bool IsLocalPull => string.IsNullOrWhiteSpace(BaseRegistry);
2727

2828
public override bool Execute()
2929
{

src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed partial class CreateNewImage : Microsoft.Build.Utilities.Task, ICa
2323
/// </summary>
2424
public string ToolPath { get; set; }
2525

26-
private bool IsLocalPull => string.IsNullOrEmpty(BaseRegistry.Trim());
26+
private bool IsLocalPull => string.IsNullOrWhiteSpace(BaseRegistry);
2727

2828
public void Cancel() => _cancellationTokenSource.Cancel();
2929

0 commit comments

Comments
 (0)