Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/NuGetizer.Tasks/CreatePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ void GeneratePackage(Stream output = null)
uri.Host.EndsWith("github.com"))
{
// expr to match markdown links with optional title. use named groups to capture the link text, url and optional title.
linkExpr ??= new Regex(@"\[(?<text>[^\]]+)\]\((?<url>[^\s)]+)(?:\s+""(?<title>[^""]*)"")?\)", RegexOptions.None);
// Handle image links inside clickable badges: [![alt](img)](url) by explicitly matching the image pattern
linkExpr ??= new Regex(@"\[(?<text>!\[[^\]]*\]\([^\)]*\)|[^\]]+)\]\((?<url>[^\s)]+)(?:\s+""(?<title>[^""]*)"")?\)", RegexOptions.None);
var repoUrl = manifest.Metadata.Repository.Url.TrimEnd('/');

// Extract owner and repo from URL for raw.githubusercontent.com format
Expand Down
37 changes: 37 additions & 0 deletions src/NuGetizer.Tests/CreatePackageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,43 @@ public void when_readme_has_image_link_then_uses_raw_url()
Assert.DoesNotContain("/blob/", readme);
}

[Fact]
public void when_readme_has_clickable_image_badge_with_relative_url_then_replaces_url()
{
var content = Path.GetTempFileName();
File.WriteAllText(content, "[![EULA](https://img.shields.io/badge/EULA-OSMF-blue)](osmfeula.txt)");
task.Contents = new[]
{
new TaskItem(content, new Metadata
{
{ MetadataName.PackageId, task.Manifest.GetMetadata("Id") },
{ MetadataName.PackFolder, PackFolderKind.None },
{ MetadataName.PackagePath, "readme.md" }
}),
};

task.Manifest.SetMetadata("Readme", "readme.md");
task.Manifest.SetMetadata("RepositoryType", "git");
task.Manifest.SetMetadata("RepositoryUrl", "https://github.com/devlooped/nugetizer");
task.Manifest.SetMetadata("RepositorySha", "abc123def");

createPackage = true;
ExecuteTask(out var manifest);

Assert.NotNull(manifest);

var file = manifest.Files.FirstOrDefault(f => Path.GetFileName(f.Target) == manifest.Metadata.Readme);
Assert.NotNull(file);
Assert.True(File.Exists(file.Source));

var readme = File.ReadAllText(file.Source);

// Should replace the relative URL in the clickable image badge
Assert.Contains("https://raw.githubusercontent.com/devlooped/nugetizer/abc123def/osmfeula.txt", readme);
// Should preserve the absolute image URL
Assert.Contains("https://img.shields.io/badge/EULA-OSMF-blue", readme);
}

[Fact]
public void when_creating_package_with_simple_dependency_then_contains_dependency_group()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFrameworks>net8.0;net8.0-windows;net8.0-maccatalyst</TargetFrameworks>
<PackOnBuild>true</PackOnBuild>
<IsPackable>true</IsPackable>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net8.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
</PropertyGroup>

<ItemGroup>
Expand Down