diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 0b4f1d1bc..384c5d618 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -133,6 +133,10 @@ class TestThermoPhase(utilities.CanteraTest): self.phase.X = 'H2:1e-1.4' self.assertArrayNear(X0, self.phase.X) + with self.assertRaises(Exception): + self.phase.X = 'H2:0.5, O2:1.0, H2:0.1' + self.assertArrayNear(X0, self.phase.X) + def test_setCompositionDict(self): self.phase.X = {b'H2':1.0, b'O2':3.0} X = self.phase.X diff --git a/src/base/stringUtils.cpp b/src/base/stringUtils.cpp index 432e77b01..deb080eaf 100644 --- a/src/base/stringUtils.cpp +++ b/src/base/stringUtils.cpp @@ -18,6 +18,7 @@ #include "cantera/base/stringUtils.h" #include "cantera/base/ctexceptions.h" #include "cantera/base/ctml.h" +#include "cantera/base/utilities.h" #include #include @@ -155,6 +156,10 @@ compositionMap parseCompString(const std::string& ss, throw CanteraError("parseCompString", "unknown species '" + name + "'"); } + if (getValue(x, name, 0.0) != 0.0) { + throw CanteraError("parseCompString", + "Duplicate key: '" + name + "'."); + } x[name] = fpValueCheck(ss.substr(valstart, stop-colon-1)); start = ss.find_first_not_of(", ;\n\t", stop+1); }