Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => (
Expand Down Expand Up @@ -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]+\//, '/')
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down