From b54a47bd02eccd2f85ed64bbe10e02db41ed51c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B8ran=20A=2E=20Slettemark?= Date: Wed, 22 Oct 2025 13:49:25 +0200 Subject: [PATCH] Strip query params --- app/interpreter.js | 4 ++++ test/interpreter.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/interpreter.js b/app/interpreter.js index 769f339..543f693 100644 --- a/app/interpreter.js +++ b/app/interpreter.js @@ -26,6 +26,7 @@ const BRANCH_TYPES = [ const PRODUCTS = ['stock', 'maps', 'gantt'] const replaceAll = (str, search, replace) => str.split(search).join(replace) +const stripQuery = (url) => (typeof url === 'string' ? url.split('?')[0] : '') /** * Finds which branch, tag, or commit that is requested by the client. Defaults @@ -34,6 +35,7 @@ const replaceAll = (str, search, replace) => str.split(search).join(replace) * @param {string} url The request URL. */ async function getBranch (url) { + url = stripQuery(url) const folders = ['adapters', 'indicators', 'modules', 'parts-3d', 'parts-map', 'parts-more', 'parts', 'themes'] const isValidBranchName = (str) => ( @@ -71,6 +73,7 @@ async function getBranch (url) { * @param {string} url The request URL. */ function getFile (branch, type, url) { + url = stripQuery(url) // Replace branches in url, since we save by commit sha url = url.replace(/^\/master/, '') url = url.replace(/^\/v[0-9]+\//, '/') @@ -173,6 +176,7 @@ function getFileOptions (files, pathJS) { * @param {string} url The request URL. */ const getType = (branch, url) => { + url = stripQuery(url) const sections = [ x => x === branch.split('/')[0], // Remove first section of branch name x => x === branch.split('/')[1], // Remove second section of branch name diff --git a/test/interpreter.js b/test/interpreter.js index 0873b3a..83986ab 100644 --- a/test/interpreter.js +++ b/test/interpreter.js @@ -47,6 +47,11 @@ describe('interpreter.js', () => { expect(await getBranch('/6.0.7')) .to.equal('6.0.7') }) + + it('should ignore query strings', async () => { + expect(await getBranch('/feature/new-api/modules/exporting.src.js?cache=123')) + .to.equal('feature/new-api') + }) }) describe('getType', () => { @@ -66,6 +71,11 @@ describe('interpreter.js', () => { expect(getType('6.0.7', '/6.0.7')) .to.equal('classic') }) + + it('should ignore query strings', () => { + expect(getType('bugfix', '/bugfix/js/modules/exporting.src.js?cache=123')) + .to.equal('css') + }) }) describe('getFile', () => { @@ -91,6 +101,11 @@ describe('interpreter.js', () => { expect(getFile('6.0.7', 'classic', '/6.0.7')) .to.equal(false) }) + + it('should ignore query strings', () => { + expect(getFile('master', 'classic', '/highcharts.js?cache=123')) + .to.equal('highcharts.src.js') + }) }) // describe('getFileOptions', () => {