Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/concerto-cto/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function modifiersFromMetaModel(mm: any): string {
break;
case `${MetaModelNamespace}.ObjectProperty`:
if (mm.defaultValue !== undefined) {
defaultString += ` default="${mm.defaultValue}"`;
defaultString += ` default=${toStringLiteral(mm.defaultValue)}`;
}
break;
}
Expand Down
62 changes: 62 additions & 0 deletions packages/concerto-cto/test/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,68 @@ describe('parser', () => {
reparsed.declarations[0].properties[0].defaultValue.should.equal('he said "hi"');
});

it('Should escape quotes and backslashes in ObjectProperty default values', () => {
const cto = Printer.toCTO({
$class: 'concerto.metamodel@1.0.0.Model',
namespace: 'org.acme@1.0.0',
imports: [],
declarations: [{
$class: 'concerto.metamodel@1.0.0.ConceptDeclaration',
name: 'C',
isAbstract: false,
properties: [{
$class: 'concerto.metamodel@1.0.0.ObjectProperty',
name: 'quoted',
type: {
$class: 'concerto.metamodel@1.0.0.TypeIdentifier',
name: 'Status'
},
isArray: false,
isOptional: false,
defaultValue: 'he said "hi"'
}, {
$class: 'concerto.metamodel@1.0.0.ObjectProperty',
name: 'slashed',
type: {
$class: 'concerto.metamodel@1.0.0.TypeIdentifier',
name: 'Status'
},
isArray: false,
isOptional: false,
defaultValue: 'a\b'
Comment thread
Shawnn08 marked this conversation as resolved.
Resolved
}]
}],
});
cto.should.include('default="he said \\"hi\\""');
cto.should.include('default="a\\b"');
});

it('Should produce parseable CTO for ObjectProperty defaults containing quotes', () => {
const cto = Printer.toCTO({
$class: 'concerto.metamodel@1.0.0.Model',
namespace: 'org.acme@1.0.0',
imports: [],
declarations: [{
$class: 'concerto.metamodel@1.0.0.ConceptDeclaration',
name: 'C',
isAbstract: false,
properties: [{
$class: 'concerto.metamodel@1.0.0.ObjectProperty',
name: 'quoted',
type: {
$class: 'concerto.metamodel@1.0.0.TypeIdentifier',
name: 'Status'
},
isArray: false,
isOptional: false,
defaultValue: 'he said "hi"'
}]
}],
});
const reparsed = Parser.parse(cto);
reparsed.declarations[0].properties[0].defaultValue.should.equal('he said "hi"');
});

it('Should escape quotes in decorator string arguments', () => {
const cto = Printer.toCTO({
$class: 'concerto.metamodel@1.0.0.Model',
Expand Down
Loading