validate field names

check for invalid characters in field names (eg '.').

Restrict character set to ascii alpha numeric and '_'.
This commit is contained in:
Michael Davidsaver
2015-09-23 15:32:46 -04:00
parent d3853bd4e9
commit f24f565e58
2 changed files with 56 additions and 1 deletions

View File

@@ -65,6 +65,24 @@ static void testCreatePVStructure()
std::cout << "testCreatePVStructure PASSED" << std::endl;
}
static void testCreatePVStructureWithInvalidName()
{
testDiag("testCreatePVStructureWithInvalidName");
StringArray fieldNames;
fieldNames.push_back("ok");
fieldNames.push_back("this.is-wrong");
PVFieldPtrArray pvFields;
pvFields.push_back(pvDataCreate->createPVScalar(pvString));
pvFields.push_back(pvDataCreate->createPVScalar(pvInt));
try{
PVStructurePtr pvParent = pvDataCreate->createPVStructure(
fieldNames,pvFields);
testFail("Creation of invalid field name '%s' was allowed", fieldNames[1].c_str());
} catch(std::invalid_argument& e) {
testPass("Creation of invalid field name '%s' fails as expected", fieldNames[1].c_str());
}
}
static void testPVScalarCommon(string /*fieldName*/,ScalarType stype)
{
PVScalarPtr pvScalar = pvDataCreate->createPVScalar(stype);
@@ -641,13 +659,14 @@ static void testFieldAccess()
MAIN(testPVData)
{
testPlan(242);
testPlan(243);
fieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
standardField = getStandardField();
standardPVField = getStandardPVField();
convert = getConvert();
testCreatePVStructure();
testCreatePVStructureWithInvalidName();
testPVScalar();
testScalarArray();
testRequest();