From 396768da7ba133bb1b49abc7f83b65854a4b4ec7 Mon Sep 17 00:00:00 2001 From: Monnte Date: Tue, 11 Mar 2025 14:22:58 +0100 Subject: [PATCH 1/2] Fix getPublicUrl to handle relative and absolute URLs --- src/utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 5dab80a..3b242b8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -119,7 +119,11 @@ function getUrlObject(req) { */ export function getPublicUrl(publicUrl, req) { if (publicUrl) { - return publicUrl; + try { + return new URL(publicUrl).toString(); + } catch { + return new URL(publicUrl, getUrlObject(req)).toString(); + } } return getUrlObject(req).toString(); } From 0053c5cd657220e58edbc769633a2ff0905188c0 Mon Sep 17 00:00:00 2001 From: Monnte Date: Tue, 11 Mar 2025 15:45:31 +0100 Subject: [PATCH 2/2] Update test expectation to allow for partial matches --- test/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/style.js b/test/style.js index 469eab7..f2af4fb 100644 --- a/test/style.js +++ b/test/style.js @@ -25,7 +25,7 @@ describe('Styles', function () { expect(res.body.sources).to.be.a('object'); expect(res.body.glyphs).to.be.a('string'); expect(res.body.sprite).to.be.a('string'); - expect(res.body.sprite).to.be.equal('/test/styles/test-style/sprite'); + expect(res.body.sprite).to.contain('/test/styles/test-style/sprite'); expect(res.body.layers).to.be.a('array'); }) .end(done);