summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRobby Zambito <contact@robbyzambito.me>2025-02-01 20:45:30 -0500
committerRobby Zambito <contact@robbyzambito.me>2025-02-11 07:15:22 -0500
commit4f940db063eb50aad0a1ca259561c29e4b83f366 (patch)
treef59928314fdbc99a9c72918a430024c930c85f5f /main.go
parenta4a003d9f4566ebfa19d1b72412608d89bd228fa (diff)
Sanitize paths
Use _ instead of . in paths. This is useful for paths like /.well-known, where the previous subject transformation would be invalid, due to two consecutive dots.
Diffstat (limited to 'main.go')
-rw-r--r--main.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/main.go b/main.go
index 14e75ae..8ab98dd 100644
--- a/main.go
+++ b/main.go
@@ -99,12 +99,13 @@ func main() {
if h, _, err := net.SplitHostPort(host); err == nil {
host = h
}
- // Use "-" instead of "." in the domain to make it a single token.
- domainParts := strings.ReplaceAll(host, ".", "-")
+ // Use "_" instead of "." in the domain to make it a single token.
+ domainParts := strings.ReplaceAll(host, ".", "_")
// Process path component
path := strings.TrimPrefix(r.URL.Path, "/")
- subjectPath := strings.ReplaceAll(path, "/", ".")
+ // Replace all "." with "_" and then all "/" with ".".
+ subjectPath := strings.ReplaceAll(strings.ReplaceAll(path, ".", "_"), "/", ".")
// Build final subject
subjectBase := "http"