Skip to content

Commit

Permalink
Merge pull request #1210 from nextstrain/dont-split-dataset-prefix
Browse files Browse the repository at this point in the history
Improve parsing of auspice URLs with a colon character
  • Loading branch information
jameshadfield authored Sep 18, 2020
2 parents 99acab5 + 886e706 commit 9f6c2c1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/actions/loadData.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ const getDataset = hasExtension("hardcodedDataPaths") ? getHardcodedData : getDa
* [1] {string | undefined} secondTreeUrl, if applicable
*/
export const collectDatasetFetchUrls = (url) => {
let secondTreeUrl;
if (url.includes(":")) {
const parts = url.replace(/^\//, '')
.replace(/\/$/, '')
.split(":");
url = parts[0]; // eslint-disable-line no-param-reassign
secondTreeUrl = parts[1];
// dual trees are defined via <pathA>:<pathB>. Note that pathA (and/or pathB) should be allowed
// to include http[s]:// (i.e. the colon there shouldn't split the string)
const re = /(?<!http[s]?):(?!\/\/)/;
if (url.search(re) !== -1) {
const treeUrls = url
.replace(/^\//, '') // strip leading forward slash
.replace(/\/$/, '') // strip trailing forward slash
.split(re); // split on the `:` character
if (treeUrls.length > 2) console.warn("Splitting of the requested dataset URL resulted in more than 2 datasets!");
return treeUrls.splice(0, 2);
}
return [url, secondTreeUrl];
return [url, undefined];
};

/**
Expand Down

0 comments on commit 9f6c2c1

Please sign in to comment.