Skip to content
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

fix: Remove all punctuation from anchors in policies.md #565

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion examples/policies-no-rego.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion internal/commands/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading