From 566bc25cbccb91a333d10df240e1eac5cad76722 Mon Sep 17 00:00:00 2001 From: Danielle Zephyr Malament Date: Tue, 17 Dec 2024 17:08:17 -0500 Subject: [PATCH] Remove all punctuation from anchors in policies.md --- examples/policies-no-rego.md | 2 +- examples/policies.md | 2 +- internal/commands/document.go | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/policies-no-rego.md b/examples/policies-no-rego.md index 6f993e83..0a0afc73 100644 --- a/examples/policies-no-rego.md +++ b/examples/policies-no-rego.md @@ -21,7 +21,7 @@ * [P2001: Images must not use the latest tag](#p2001-images-must-not-use-the-latest-tag) * [P2002: Containers must define resource constraints](#p2002-containers-must-define-resource-constraints) * [P2005: Roles must not allow use of privileged PodSecurityPolicies](#p2005-roles-must-not-allow-use-of-privileged-podsecuritypolicies) -* [P2006: Tenants' containers must not run as privileged](#p2006-tenants'-containers-must-not-run-as-privileged) +* [P2006: Tenants' containers must not run as privileged](#p2006-tenants-containers-must-not-run-as-privileged) ## Warnings diff --git a/examples/policies.md b/examples/policies.md index 39b88e69..a6cb225a 100755 --- a/examples/policies.md +++ b/examples/policies.md @@ -21,7 +21,7 @@ * [P2001: Images must not use the latest tag](#p2001-images-must-not-use-the-latest-tag) * [P2002: Containers must define resource constraints](#p2002-containers-must-define-resource-constraints) * [P2005: Roles must not allow use of privileged PodSecurityPolicies](#p2005-roles-must-not-allow-use-of-privileged-podsecuritypolicies) -* [P2006: Tenants' containers must not run as privileged](#p2006-tenants'-containers-must-not-run-as-privileged) +* [P2006: Tenants' containers must not run as privileged](#p2006-tenants-containers-must-not-run-as-privileged) ## Warnings diff --git a/internal/commands/document.go b/internal/commands/document.go index f76b01e5..7bd3a4f6 100644 --- a/internal/commands/document.go +++ b/internal/commands/document.go @@ -186,7 +186,14 @@ func getDocumentation(path string, outputDirectory string) (map[rego.Severity][] } anchor := strings.ToLower(strings.ReplaceAll(documentTitle, " ", "-")) - anchor = strings.ReplaceAll(anchor, ":", "") + // Tab and all ASCII punctuation except - and _ + punctReplacer := strings.NewReplacer( + "\t", "", "!", "", "\"", "", "#", "", "$", "", "%", "", "&", "", "'", "", "(", "", ")", "", + "*", "", "+", "", ",", "", ".", "", "/", "", ":", "", ";", "", "<", "", "=", "", ">", "", + "?", "", "@", "", "[", "", "\\", "", "]", "", "^", "", "`", "", "{", "", "|", "", "}", "", + "~", "", + ) + anchor = punctReplacer.Replace(anchor) legacyMatchers, err := policy.Matchers() if err != nil {