fail zero length field names

This commit is contained in:
Michael Davidsaver
2015-09-24 13:04:49 -04:00
parent f24f565e58
commit 3714be4f16
2 changed files with 9 additions and 3 deletions

View File

@@ -948,14 +948,19 @@ StructureConstPtr FieldCreate::createStructure () const
}
namespace {
bool xisalnum(char c)
{
return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9');
}
void validateFieldName(const std::string& n)
{
if(n.size()==0)
throw std::invalid_argument("zero length field names not allowed");
for(size_t i=0, N=n.size(); i<N; i++)
{
char c = n[i];
if(c>='a' && c<='z') {}
else if(c>='A' && c<='Z') {}
else if(c>='0' && c<='9') {}
if(xisalnum(c)) {}
else {
switch(c){
case '_':

View File

@@ -79,6 +79,7 @@ static void testCreatePVStructureWithInvalidName()
fieldNames,pvFields);
testFail("Creation of invalid field name '%s' was allowed", fieldNames[1].c_str());
} catch(std::invalid_argument& e) {
testDiag("Exception: \"%s\"", e.what());
testPass("Creation of invalid field name '%s' fails as expected", fieldNames[1].c_str());
}
}