From 08ea7d5137553f0b99f8d87e188c17f17293073d Mon Sep 17 00:00:00 2001 From: Colin Megill Date: Tue, 5 Feb 2019 10:44:59 -0500 Subject: [PATCH] Better input validation (#580) --- client/src/components/geneExpression/index.js | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/client/src/components/geneExpression/index.js b/client/src/components/geneExpression/index.js index 8c1f53f7..43981bcb 100644 --- a/client/src/components/geneExpression/index.js +++ b/client/src/components/geneExpression/index.js @@ -108,21 +108,29 @@ class GeneExpression extends React.Component { const { world, dispatch, userDefinedGenes } = this.props; const { bulkAdd } = this.state; - const genes = _.uniq(bulkAdd.split(", ").map(g => g.trim())); + /* + test: + Apod,,, Cd74,, ,,, Foo, Bar-2,, + */ + if (bulkAdd !== "") { + const genes = _.pull(_.uniq(bulkAdd.split(/[ ,]+/)), ""); - genes.forEach(gene => { - if (userDefinedGenes.indexOf(gene) !== -1) { - keepAroundErrorToast("That gene already exists"); - } else if (!_.find(world.varAnnotations, { name: gene })) { - keepAroundErrorToast(`${gene} doesn't appear to be a valid gene name.`); - } else { - dispatch(actions.requestUserDefinedGene(gene)); - dispatch({ - type: "user defined gene", - data: gene - }); - } - }); + genes.forEach(gene => { + if (userDefinedGenes.indexOf(gene) !== -1) { + keepAroundErrorToast("That gene already exists"); + } else if (!_.find(world.varAnnotations, { name: gene })) { + keepAroundErrorToast( + `${gene} doesn't appear to be a valid gene name.` + ); + } else { + dispatch(actions.requestUserDefinedGene(gene)); + dispatch({ + type: "user defined gene", + data: gene + }); + } + }); + } this.setState({ bulkAdd: "" }); } @@ -230,9 +238,6 @@ class GeneExpression extends React.Component { { - console.log("heyo"); - }} >