Skip to content

Commit

Permalink
fix(lib): deprecate placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Oguz Eroglu committed Dec 10, 2019
1 parent 24cf812 commit 890f9f5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
13 changes: 0 additions & 13 deletions lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ var QNAME_REGEX = /^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i;
// for ID validation as per BPMN Schema (QName - Namespace)
var ID_REGEX = /^[a-z_][\w-.]*$/i;

var PLACEHOLDER_REGEX = /\$\{([^}]*)\}/g;

var HTML_ESCAPE_MAP = {
'&': '&',
'<': '&lt;',
Expand Down Expand Up @@ -152,8 +150,6 @@ export function isIdValid(bo, idValue, translate) {

export function validateId(idValue, translate) {

idValue = stripPlaceholders(idValue);

if (containsSpace(idValue)) {
return translate('Id must not contain spaces.');
}
Expand All @@ -173,15 +169,6 @@ export function containsSpace(value) {
return SPACE_REGEX.test(value);
}


function stripPlaceholders(idValue) {

// replace expression e.g. ${VERSION_TAG}
// use only the content between ${}
// for the REGEX check
return idValue.replace(PLACEHOLDER_REGEX, '$1');
}

/**
* generate a semantic id with given prefix
*/
Expand Down
2 changes: 1 addition & 1 deletion test/spec/UtilsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Utils', function() {
it('may NOT start with numbers', validate('9ba', 'Id must be a valid QName.'));
it('may NOT start prefix with numbers', validate('9ba:foo', 'Id must be a valid QName.'));

it('may contain ${} placeholders', validate('${foo}ba99'));
it('may NOT contain ${} placeholders', validate('${foo}ba99', 'Id must be a valid QName.'));
it('may NOT contain empty placeholders', validate('${}', 'Id must be a valid QName.'));
});

Expand Down
20 changes: 8 additions & 12 deletions test/spec/provider/dmn/IdSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('id-properties', function() {
}));


it('should set the id with the expression at the beginning', function() {
it('should not set the id with the expression at the beginning', function() {

// assume
expect(textField.value).to.equal('dish-decision');
Expand All @@ -146,12 +146,11 @@ describe('id-properties', function() {
triggerValue(textField, '${VERSION_TAG}_foo', 'change');

// then
expect(getTextField().value).to.equal('${VERSION_TAG}_foo');
expect(businessObject.get('id')).to.equal('${VERSION_TAG}_foo');
expect(businessObject.get('id')).to.equal('dish-decision');
});


it('should set the id with the expression at the end', function() {
it('should not set the id with the expression at the end', function() {

// assume
expect(textField.value).to.equal('dish-decision');
Expand All @@ -160,12 +159,11 @@ describe('id-properties', function() {
triggerValue(textField, 'foo_${VERSION_TAG}', 'change');

// then
expect(getTextField().value).to.equal('foo_${VERSION_TAG}');
expect(businessObject.get('id')).to.equal('foo_${VERSION_TAG}');
expect(businessObject.get('id')).to.equal('dish-decision');
});


it('should set the id with the expression in the middle', function() {
it('should not set the id with the expression in the middle', function() {

// assume
expect(textField.value).to.equal('dish-decision');
Expand All @@ -174,12 +172,11 @@ describe('id-properties', function() {
triggerValue(textField, 'foo_${VERSION_TAG}_bar', 'change');

// then
expect(getTextField().value).to.equal('foo_${VERSION_TAG}_bar');
expect(businessObject.get('id')).to.equal('foo_${VERSION_TAG}_bar');
expect(businessObject.get('id')).to.equal('dish-decision');
});


it('should set the id which is only an expression', function() {
it('should not set the id which is only an expression', function() {

// assume
expect(textField.value).to.equal('dish-decision');
Expand All @@ -188,8 +185,7 @@ describe('id-properties', function() {
triggerValue(textField, '${VERSION_TAG}', 'change');

// then
expect(getTextField().value).to.equal('${VERSION_TAG}');
expect(businessObject.get('id')).to.equal('${VERSION_TAG}');
expect(businessObject.get('id')).to.equal('dish-decision');
});


Expand Down

0 comments on commit 890f9f5

Please sign in to comment.