Skip to content

Commit 6bcfb1f

Browse files
committed
playwright: verify that URLs with question marks work
Some book sections' titles end in a question mark. In URLs, question marks are interpreted as the separator between the path part and the query string. This matters because the book sections' titles are used to construct their URLs. We want to follow Postel's Law and accept even URLs with non-URI-encoded question marks, gracefully redirecting to the correct URL. Add code to the Playwright-based tests to that extent. While at it, also verify that the redirection uses proper URI-encoding for non-ASCII characters; This requires a minor improvement of the intentionally very simplistic `serve-public.js` script. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2f160a5 commit 6bcfb1f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

script/serve-public.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const mimeTypes = {
2424
};
2525

2626
const handler = (request, response) => {
27-
const pathname = url.parse(request.url).pathname;
27+
const pathname = decodeURIComponent(url.parse(request.url).pathname);
2828
let filename = path.join(basePath, pathname === "/" ? "index.html" : pathname);
2929

3030
let stats = fs.statSync(filename, { throwIfNoEntry: false });

tests/git-scm.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,14 @@ test('book', async ({ page }) => {
193193
await page.getByRole('link', { name: 'Français' }).click()
194194
await expect(page).toHaveURL(/book\/fr/)
195195
await expect(page.getByRole('link', { name: 'Démarrage rapide' })).toBeVisible()
196+
197+
// Navigate to a page whose URL contains a question mark
198+
await page.goto(`${url}book/az/v2/Başlanğıc-Git-Nədir?`)
199+
if (isRailsApp) {
200+
await expect(page).toHaveURL(/book\/az\/v2$/)
201+
await page.goto(`${url}book/az/v2/Başlanğıc-Git-Nədir%3F`)
202+
} else {
203+
await expect(page).toHaveURL(/Ba%C5%9Flan%C4%9F%C4%B1c-Git-N%C9%99dir%3F/)
204+
}
205+
await expect(page.getByRole('document')).toHaveText(/Snapshotlar, Fərqlər Yox/)
196206
})

0 commit comments

Comments
 (0)