Skip to content

Commit

Permalink
Reconciled parsing of field names with Substitution Field Spec. (#82)
Browse files Browse the repository at this point in the history
According to the spec., valid syntax for merge field names is determined
by the merge source with a couple of minor exceptions.  Current text backends
allow any printable characters, so the SubstitutionField parser now accepts
any printable characters.
  • Loading branch information
jimevins committed Jan 1, 2020
1 parent aebcda4 commit 2d56507
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion model/SubstitutionField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace glabels
{
bool success = false;

while ( s.size() && (s[0].isDigit() || s[0].isLetter() || s[0] == '_' || s[0] == '-') )
while ( s.size() && (s[0].isPrint() && s[0] != ':' && s[0] != '}') )
{
field.mFieldName.append( s[0] );
s = s.mid(1);
Expand Down
24 changes: 23 additions & 1 deletion model/unit_tests/TestSubstitutionField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void TestSubstitutionField::parseValid()
//
// Valid substitution fields (concatenated in single input string)
//
QString input = "${1234}${abc:=ABC}${x:%08.2f}${y:%08.2f:=12.34}${ADDR2:n}";
QString input = "${1234}${abc:=ABC}${x:%08.2f}${y:%08.2f:=12.34}${ADDR2:n}${FüññýßútLæg@lѪmê}${Also_a legal-name}";
QStringRef s = &input;

model::SubstitutionField f1;
Expand Down Expand Up @@ -66,6 +66,16 @@ void TestSubstitutionField::parseValid()
QCOMPARE( model::SubstitutionField::parse( s, f5 ), true );
QCOMPARE( f5.fieldName(), QString( "ADDR2" ) );
QCOMPARE( f5.newLine(), true );

model::SubstitutionField f6;
QCOMPARE( model::SubstitutionField::parse( s, f6 ), true );
QCOMPARE( f6.fieldName(), QString( "FüññýßútLæg@lѪmê" ) );
QCOMPARE( f6.newLine(), false );

model::SubstitutionField f7;
QCOMPARE( model::SubstitutionField::parse( s, f7 ), true );
QCOMPARE( f7.fieldName(), QString( "Also_a legal-name" ) );
QCOMPARE( f7.newLine(), false );
}


Expand Down Expand Up @@ -108,6 +118,18 @@ void TestSubstitutionField::parseInvalid()
QStringRef s9 = &input9;
model::SubstitutionField f9;
QCOMPARE( model::SubstitutionField::parse( s9, f9 ), true );

QString input10 = "${embedded\nnew-line}";
QStringRef s10 = &input10;
model::SubstitutionField f10;
QCOMPARE( model::SubstitutionField::parse( s10, f10 ), false );
QCOMPARE( s10, QStringRef( &input10 ) ); // Should not advance string reference

QString input11 = "${how-about-a\ttab}";
QStringRef s11 = &input11;
model::SubstitutionField f11;
QCOMPARE( model::SubstitutionField::parse( s11, f11 ), false );
QCOMPARE( s11, QStringRef( &input11 ) ); // Should not advance string reference
}


Expand Down

0 comments on commit 2d56507

Please sign in to comment.