mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
Check for correctly sized propertylists to avoid dropping molecules (#8921)
* Fixes #8918 * Use only the one check for compatible sizes --------- Co-authored-by: Brian Kelley <bkelley@glysade.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#define RD_FILEPARSERUTILS_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <RDGeneral/BoostStartInclude.h>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@@ -119,12 +120,6 @@ void applyMolListProp(ROMol &mol, const std::string &pn,
|
||||
std::vector<std::string> tokens;
|
||||
boost::split(tokens, strVect, boost::is_any_of(" \t\n"),
|
||||
boost::token_compress_on);
|
||||
if (tokens.size() < nItems) {
|
||||
BOOST_LOG(rdWarningLog) << "Property list " << pn << " too short, only "
|
||||
<< tokens.size() << " elements found; expecting "
|
||||
<< nItems << ". Ignoring it." << std::endl;
|
||||
return;
|
||||
}
|
||||
std::string mv = missingValueMarker;
|
||||
size_t first_token = 0;
|
||||
if (tokens.size() == nItems + 1 && tokens[0].front() == '[' &&
|
||||
@@ -136,6 +131,12 @@ void applyMolListProp(ROMol &mol, const std::string &pn,
|
||||
BOOST_LOG(rdWarningLog) << "Missing value marker for property " << pn
|
||||
<< " is empty." << std::endl;
|
||||
}
|
||||
if(tokens.size() - first_token != nItems) {
|
||||
BOOST_LOG(rdWarningLog) << "Property list " << pn << " has incompatible size, "
|
||||
<< tokens.size() << " elements found; expecting "
|
||||
<< nItems << ". Ignoring it." << std::endl;
|
||||
return;
|
||||
}
|
||||
for (size_t i = first_token; i < tokens.size(); ++i) {
|
||||
if (tokens[i] != mv) {
|
||||
unsigned int itemid = i - first_token;
|
||||
|
||||
@@ -188,6 +188,9 @@ one n/a three
|
||||
> <bond.prop.foo> (1)
|
||||
bar baz blah
|
||||
|
||||
> <atom.iprop.TooLong> (1)
|
||||
0 1 2 3 4
|
||||
|
||||
$$$$
|
||||
)SDF";
|
||||
SECTION("no processing") {
|
||||
@@ -210,6 +213,9 @@ $$$$
|
||||
std::string val;
|
||||
CHECK(m->getBondWithIdx(0)->getPropIfPresent("foo", val));
|
||||
CHECK(val == "bar");
|
||||
|
||||
CHECK(m->hasProp("atom.iprop.TooLong"));
|
||||
CHECK(!m->getAtomWithIdx(0)->hasProp("TooLong"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user