diff --git a/routes/appendLocals.js b/routes/appendLocals.js
index 5c4fb7792..463387210 100644
--- a/routes/appendLocals.js
+++ b/routes/appendLocals.js
@@ -1,6 +1,7 @@
'use strict';
const path = require('path');
+const url = require('url');
const { generateSri, capitalize } = require('../lib/helpers');
const { app, files } = require('../config');
@@ -58,11 +59,9 @@ function generateSRI(file) {
function appendLocals(req, res) {
const siteUrl = getCurrentSiteurl(req);
const pageUrl = req.originalUrl;
- // OK, hack-ish way...
- const pathname = pageUrl.split('?')[0];
- const canonicalUrl = new URL(pathname, app.siteurl);
+ const canonicalUrl = url.resolve(app.siteurl, url.parse(pageUrl).pathname);
const theme = getThemeQuery(req);
- const bodyClass = generateBodyClass(pathname);
+ const bodyClass = generateBodyClass(pageUrl);
const locals = {
siteUrl,
diff --git a/test/test_helpers.js b/test/test_helpers.js
index a0e28ae9e..d13792430 100644
--- a/test/test_helpers.js
+++ b/test/test_helpers.js
@@ -6,6 +6,7 @@ const ENV = process.env;
ENV.BCDN_HEADERS = ENV.BCDN_HEADERS || 'production';
const assert = require('assert').strict;
+const url = require('url');
const escapeStringRegexp = require('escape-string-regexp');
const { htmlEncode } = require('htmlencode');
const mockDate = require('mockdate');
@@ -141,7 +142,7 @@ function assertPageHeader(txt, res, cb) {
}
function assertCanonicalUrl(str, res, cb) {
- const expected = ``;
+ const expected = ``;
assert.ok(res.body.includes(expected), 'Expects page to have a canonical URL');
cb();