Skip to content

Commit

Permalink
fix: escape names that might collide with other operations
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta authored Sep 15, 2023
2 parents e8caf27 + abe966b commit 78aa307
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 10 deletions.
31 changes: 23 additions & 8 deletions munge_aggregates.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const main = async () => {

for (const row of testsRows) {
const { versions, full_name, name, parent_test_full_name } = row;
const slug = slugify(full_name);
const slug = slugifyTestName(full_name);

if (!groups[parent_test_full_name]) {
groups[parent_test_full_name] = {};
Expand Down Expand Up @@ -285,7 +285,7 @@ const main = async () => {

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

const testsTaxonomy = {};
for (const row of testsTaxonomyRows) {
const { full_name, name, test_run_implementation_id, test_run_version } = row;
const slug = slugify(full_name);
const { full_name, test_run_implementation_id, test_run_version } = row;
const slug = slugifyTestName(full_name);
const name = decodeURIComponent(row.name);

if (!testsTaxonomy[full_name]) {
testsTaxonomy[full_name] = {
Expand Down Expand Up @@ -349,6 +350,7 @@ const main = async () => {
test_run_implementation_id AS implementation_id,
test_run_version AS version,
full_name,
name,
outcome
FROM TestResult
ORDER BY test_run_implementation_id, test_run_version, full_name
Expand All @@ -358,7 +360,8 @@ const main = async () => {
const resultsTaxonomy = {};
for (const row of resultsTaxonomyRows) {
const { implementation_id, version, full_name, outcome } = row;
const slug = slugify(full_name);
const slug = slugifyTestName(full_name);
const name = decodeURIComponent(row.name);

if (!resultsTaxonomy[implementation_id]) {
resultsTaxonomy[implementation_id] = {};
Expand All @@ -371,6 +374,7 @@ const main = async () => {
if (!resultsTaxonomy[implementation_id][version][full_name]) {
resultsTaxonomy[implementation_id][version][full_name] = {
slug,
name,
full_name,
outcome,
};
Expand All @@ -395,7 +399,7 @@ const main = async () => {
...test,
implementation_id,
version,
title: test.full_name
title: test.name
});
}
}
Expand All @@ -418,12 +422,23 @@ const slugify = (str) => {
.trim() // trim leading or trailing whitespace
.toLowerCase() // convert to lowercase
.replace(/\s+/g, '_') // replace spaces with underscore
.replace(/[.,()"/]/g, '-') // remove the characters (, ) and ~
.replace(/[^a-z0-9 -\/]/g, '-') // remove non-alphanumeric characters
.replace(/_+/g, '_') // remove consecutive underscores
.replace(/[\/]/g, "__")
.replace(/[^a-z0-9 -]/g, '-') // remove non-alphanumeric characters
.replace(/-+/g, '-') // remove consecutive dashes
}

const slugifyTestName = (str) => {
let x = String(str).split('/');
x = x.map(part => {
// url decode to handle %20, etc
part = decodeURIComponent(part);
return slugify(part.replace(/([a-z])([A-Z])/g, '$1-$2') // Convert CamelCase to kebab-case
)
})
return x.join('/');
}

const outputJSON = (p, data) => {
const json = JSON.stringify(data, null, 2);
const fullPath = `${hugoOutput}/${p}`;
Expand Down
21 changes: 19 additions & 2 deletions tooling/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package test
import (
"context"
"net/http"
"net/url"
"strings"
"testing"
"time"

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

name := safeName(test.Name)

if len(test.Requests) > 0 {
t.Run(test.Name, func(t *testing.T) {
t.Run(name, func(t *testing.T) {
tooling.LogSpecs(t, test.AllSpecs()...)
responses := make([]*http.Response, 0, len(test.Requests))

Expand All @@ -82,11 +86,24 @@ func run(t *testing.T, tests SugarTests) {
validateResponses(t, test.Responses, responses)
})
} else {
t.Run(test.Name, func(t *testing.T) {
t.Run(name, func(t *testing.T) {
tooling.LogSpecs(t, test.AllSpecs()...)
_, res, localReport := runRequest(timeout, t, test, test.Request)
validateResponse(t, test.Response, res, localReport)
})
}
}
}

func safeName(s string) string {
// Split the string by spaces
parts := strings.Split(s, " ")

// Escape each part
for i, part := range parts {
parts[i] = url.PathEscape(part)
}

// Join the parts back together with spaces
return strings.Join(parts, " ")
}
4 changes: 4 additions & 0 deletions www/content/results/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Tests
redirectsTo: /current
---
4 changes: 4 additions & 0 deletions www/content/tests/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Tests
redirectsTo: /current
---
6 changes: 6 additions & 0 deletions www/themes/conformance/layouts/partials/head.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
{{ $styles := resources.Get "style.css" }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}">

{{ with .Params.RedirectsTo }}
<meta http-equiv="refresh" content="0; url={{ . | absURL }}"/>
{{ end }}

{{ .Params.RedirectsTo }}

0 comments on commit 78aa307

Please sign in to comment.