Skip to content

Commit 78aa307

Browse files
authored
fix: escape names that might collide with other operations
2 parents e8caf27 + abe966b commit 78aa307

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

munge_aggregates.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const main = async () => {
107107

108108
for (const row of testsRows) {
109109
const { versions, full_name, name, parent_test_full_name } = row;
110-
const slug = slugify(full_name);
110+
const slug = slugifyTestName(full_name);
111111

112112
if (!groups[parent_test_full_name]) {
113113
groups[parent_test_full_name] = {};
@@ -285,7 +285,7 @@ const main = async () => {
285285

286286
const testResults = {};
287287
for (const row of rows) {
288-
testResults[row.full_name] = { ...row, slug: slugify(row.full_name) };
288+
testResults[row.full_name] = { ...row, slug: slugifyTestName(row.full_name) };
289289
}
290290
outputJSON(`data/testresults/${id}/${version}.json`, testResults);
291291
}
@@ -310,8 +310,9 @@ const main = async () => {
310310

311311
const testsTaxonomy = {};
312312
for (const row of testsTaxonomyRows) {
313-
const { full_name, name, test_run_implementation_id, test_run_version } = row;
314-
const slug = slugify(full_name);
313+
const { full_name, test_run_implementation_id, test_run_version } = row;
314+
const slug = slugifyTestName(full_name);
315+
const name = decodeURIComponent(row.name);
315316

316317
if (!testsTaxonomy[full_name]) {
317318
testsTaxonomy[full_name] = {
@@ -349,6 +350,7 @@ const main = async () => {
349350
test_run_implementation_id AS implementation_id,
350351
test_run_version AS version,
351352
full_name,
353+
name,
352354
outcome
353355
FROM TestResult
354356
ORDER BY test_run_implementation_id, test_run_version, full_name
@@ -358,7 +360,8 @@ const main = async () => {
358360
const resultsTaxonomy = {};
359361
for (const row of resultsTaxonomyRows) {
360362
const { implementation_id, version, full_name, outcome } = row;
361-
const slug = slugify(full_name);
363+
const slug = slugifyTestName(full_name);
364+
const name = decodeURIComponent(row.name);
362365

363366
if (!resultsTaxonomy[implementation_id]) {
364367
resultsTaxonomy[implementation_id] = {};
@@ -371,6 +374,7 @@ const main = async () => {
371374
if (!resultsTaxonomy[implementation_id][version][full_name]) {
372375
resultsTaxonomy[implementation_id][version][full_name] = {
373376
slug,
377+
name,
374378
full_name,
375379
outcome,
376380
};
@@ -395,7 +399,7 @@ const main = async () => {
395399
...test,
396400
implementation_id,
397401
version,
398-
title: test.full_name
402+
title: test.name
399403
});
400404
}
401405
}
@@ -418,12 +422,23 @@ const slugify = (str) => {
418422
.trim() // trim leading or trailing whitespace
419423
.toLowerCase() // convert to lowercase
420424
.replace(/\s+/g, '_') // replace spaces with underscore
425+
.replace(/[.,()"/]/g, '-') // remove the characters (, ) and ~
426+
.replace(/[^a-z0-9 -\/]/g, '-') // remove non-alphanumeric characters
421427
.replace(/_+/g, '_') // remove consecutive underscores
422-
.replace(/[\/]/g, "__")
423-
.replace(/[^a-z0-9 -]/g, '-') // remove non-alphanumeric characters
424428
.replace(/-+/g, '-') // remove consecutive dashes
425429
}
426430

431+
const slugifyTestName = (str) => {
432+
let x = String(str).split('/');
433+
x = x.map(part => {
434+
// url decode to handle %20, etc
435+
part = decodeURIComponent(part);
436+
return slugify(part.replace(/([a-z])([A-Z])/g, '$1-$2') // Convert CamelCase to kebab-case
437+
)
438+
})
439+
return x.join('/');
440+
}
441+
427442
const outputJSON = (p, data) => {
428443
const json = JSON.stringify(data, null, 2);
429444
const fullPath = `${hugoOutput}/${p}`;

tooling/test/test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package test
33
import (
44
"context"
55
"net/http"
6+
"net/url"
7+
"strings"
68
"testing"
79
"time"
810

@@ -68,8 +70,10 @@ func run(t *testing.T, tests SugarTests) {
6870
timeout, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
6971
defer cancel()
7072

73+
name := safeName(test.Name)
74+
7175
if len(test.Requests) > 0 {
72-
t.Run(test.Name, func(t *testing.T) {
76+
t.Run(name, func(t *testing.T) {
7377
tooling.LogSpecs(t, test.AllSpecs()...)
7478
responses := make([]*http.Response, 0, len(test.Requests))
7579

@@ -82,11 +86,24 @@ func run(t *testing.T, tests SugarTests) {
8286
validateResponses(t, test.Responses, responses)
8387
})
8488
} else {
85-
t.Run(test.Name, func(t *testing.T) {
89+
t.Run(name, func(t *testing.T) {
8690
tooling.LogSpecs(t, test.AllSpecs()...)
8791
_, res, localReport := runRequest(timeout, t, test, test.Request)
8892
validateResponse(t, test.Response, res, localReport)
8993
})
9094
}
9195
}
9296
}
97+
98+
func safeName(s string) string {
99+
// Split the string by spaces
100+
parts := strings.Split(s, " ")
101+
102+
// Escape each part
103+
for i, part := range parts {
104+
parts[i] = url.PathEscape(part)
105+
}
106+
107+
// Join the parts back together with spaces
108+
return strings.Join(parts, " ")
109+
}

www/content/results/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Tests
3+
redirectsTo: /current
4+
---

www/content/tests/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Tests
3+
redirectsTo: /current
4+
---
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
{{ $styles := resources.Get "style.css" }}
22
<link rel="stylesheet" href="{{ $styles.RelPermalink }}">
3+
4+
{{ with .Params.RedirectsTo }}
5+
<meta http-equiv="refresh" content="0; url={{ . | absURL }}"/>
6+
{{ end }}
7+
8+
{{ .Params.RedirectsTo }}

0 commit comments

Comments
 (0)