Skip to content

Commit 3cace7e

Browse files
committed
Do not strip underscores from changes descriptions
Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
1 parent 1c7148b commit 3cace7e

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

internal/pkg/manager.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func (m *Manager) Register(ctx context.Context, pkg *hub.Package) error {
301301

302302
// Strip markdown from changes entries description
303303
for _, change := range pkg.Changes {
304-
change.Description = stripmd.Strip(change.Description)
304+
change.Description = stripChangeDescription(change.Description)
305305
}
306306

307307
// Register package in database
@@ -443,3 +443,22 @@ func areValidCapabilities(capabilities string) bool {
443443
}
444444
return false
445445
}
446+
447+
// stripChangeDescription removes markdown while preserving underscores.
448+
func stripChangeDescription(description string) string {
449+
// Fast path for descriptions without underscores
450+
if !strings.Contains(description, "_") {
451+
return stripmd.Strip(description)
452+
}
453+
454+
// Protect underscores before stripping markdown
455+
token := "UNDERSCORETOKEN"
456+
for strings.Contains(description, token) {
457+
token += "X"
458+
}
459+
protected := strings.ReplaceAll(description, "_", token)
460+
461+
// Strip markdown and restore underscores
462+
stripped := stripmd.Strip(protected)
463+
return strings.ReplaceAll(stripped, token, "_")
464+
}

internal/pkg/manager_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,3 +1564,32 @@ func TestParseKey(t *testing.T) {
15641564
})
15651565
}
15661566
}
1567+
1568+
func TestStripChangeDescription(t *testing.T) {
1569+
t.Parallel()
1570+
1571+
testCases := []struct {
1572+
description string
1573+
expected string
1574+
}{
1575+
{
1576+
description: "Suppress CONFIG_OPTION_NAME warning and *bold* text",
1577+
expected: "Suppress CONFIG_OPTION_NAME warning and bold text",
1578+
},
1579+
{
1580+
description: "No markdown or underscores here",
1581+
expected: "No markdown or underscores here",
1582+
},
1583+
{
1584+
description: "Token collision UNDERSCORETOKEN and CONFIG_OPTION_NAME",
1585+
expected: "Token collision UNDERSCORETOKEN and CONFIG_OPTION_NAME",
1586+
},
1587+
}
1588+
1589+
for _, tc := range testCases {
1590+
t.Run(tc.description, func(t *testing.T) {
1591+
t.Parallel()
1592+
assert.Equal(t, tc.expected, stripChangeDescription(tc.description))
1593+
})
1594+
}
1595+
}

0 commit comments

Comments
 (0)