Skip to content

Commit

Permalink
Fixed text and code.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed Dec 6, 2023
1 parent af8a890 commit 0364210
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/formats/newick.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ export function getNewick(annotator, root) {
if(n.data.name !== 'root') {
const node_label = n.data.name.replaceAll("'", "''");

// Escape the entire string if it contains any whitespace.
if (/\w/.test(node_label)) {
// Surround the entire string with single quotes if it contains any
// non-alphanumeric characters.
if (/\W/.test(node_label)) {
element_array.push("'" + node_label + "'");
} else {
element_array.push(node_label);
Expand Down
6 changes: 3 additions & 3 deletions test/formats-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ tape("Handle Newick strings with spaces", function(test) {
* can read and write Newick strings correctly.
*/

let nwk = "('Alpha beta', ('Alpha gamma', ('Delta''s epsilon', 'Epsilon zeta ''alphonso''', 'test''')))";
let nwk = "('Alpha beta', ('Alpha gamma', ('Delta''s epsilon', 'Epsilon zeta ''alphonso''', 'test''s')))";
let phylo = new phylotree.phylotree(nwk);

let test_leaves = ['Alpha beta', 'Alpha gamma', "Delta's epsilon", "Epsilon zeta 'alphonso'", "test'"];
let test_leaves = ['Alpha beta', 'Alpha gamma', "Delta's epsilon", "Epsilon zeta 'alphonso'", "test's"];
test_leaves.forEach(function(leaf) {
let node = phylo.getNodeByName(leaf);
test.equal(node.data.name, leaf);
Expand All @@ -94,7 +94,7 @@ tape("Handle Newick strings with spaces", function(test) {
// This would be identical to the original Newick string, but phylotree.js coerces
// lengths to 1 (see https://github.com/veg/phylotree.js/issues/440). So we expect
// all lengths to be set to 1 on export.
test.equal(phylo.getNewick(), "('Alpha beta':1,('Alpha gamma':1,('Delta''s epsilon':1,'Epsilon zeta ''alphonso''':1,'test''':1):1):1):1;");
test.equal(phylo.getNewick(), "('Alpha beta':1,('Alpha gamma':1,('Delta''s epsilon':1,'Epsilon zeta ''alphonso''':1,'test''s':1):1):1):1;");

test.end();
});

0 comments on commit 0364210

Please sign in to comment.