From 2413e3c9886c65e0f675379f793edc96e98c0379 Mon Sep 17 00:00:00 2001 From: James Hadfield Date: Thu, 7 Dec 2023 12:10:25 +1300 Subject: [PATCH] Disallow newick trees with quotes The newick parser we use is known to have issues with quoted node names, as it will parse the node name content as newick. As a quick fix, disallow trees with quotes. The result is that the trees in #66 and will now result in an error. The downside is trees with quoted names but no newick-like structure within the node name will also fail to load. --- auspice_client_customisation/parseNewick.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/auspice_client_customisation/parseNewick.js b/auspice_client_customisation/parseNewick.js index 768a72b..32e0d76 100644 --- a/auspice_client_customisation/parseNewick.js +++ b/auspice_client_customisation/parseNewick.js @@ -19,6 +19,17 @@ export const parseNewick = (nwk) => { const ancestors = []; let tree = {}; + + /** + * This newick parser is known to have issues with quoted node names, as it + * will parse the node name content as newick. As a quick fix, disallow trees + * with quotes. + */ + if (nwk.includes('"') || nwk.includes("'")) { + throw new Error("Auspice.us cannot currently parse Newick files with single or double quotes in them!") + } + + const tokens = nwk.split(/\s*(;|\(|\)|,|:)\s*/); for (let i=0; i