Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Improve null value validation #126

Merged
merged 4 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Versioning](http://semver.org/spec/v2.0.0.html).
### Fixed
- Merge PR #120, fixing dependency issue with "@types/colors"
- Merge PR #127, implementing "safer-buffer" polyfill to be compatible with older NodeJS versions
- Merge PR #126, improving null value validation when null is passed into a template

## [1.5.1] - 2018-03-12
### Added
Expand Down
10 changes: 9 additions & 1 deletion src/test/validatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,15 @@ describe('validator', () => {
let result = validator.validateFile(input);
expect(result).to.have.deep.property('templateValid', true);
expect(result['errors']['crit']).to.have.lengthOf(0);
})
});

it('a null property value should not cause an exception', () => {
const input = 'testData/invalid/yaml/null_value.yaml';
let result = validator.validateFile(input);
expect(result).to.have.deep.property('templateValid', false);
expect(result['errors']['crit']).to.have.lengthOf(1);
expect(result['errors']['crit'][0]).to.have.property('message', 'Expecting a list, got null');
});
});

describe('parameters-validation', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ function recursiveDecent(ref: any){
lastPositionInTemplate[lastPositionInTemplateKey] = functionOutput;
}
}
}else if(key != 'Attributes' && typeof ref[key] == "object"){
}else if(key != 'Attributes' && ref[key] instanceof Object){
placeInTemplate.push(key);
lastPositionInTemplate = ref;
lastPositionInTemplateKey = key;
Expand Down Expand Up @@ -1418,12 +1418,12 @@ function verificationFunction(f: (o: any) => boolean, message: string): Verifica
}

export const isList = verificationFunction(
(o: any) => (typeof o === 'object' && o.constructor === Array),
(o: any) => (o instanceof Object && o.constructor === Array),
'Expecting a list'
);

export const isObject = verificationFunction(
(o: any) => (typeof o === 'object' && o.constructor === Object),
(o: any) => (o instanceof Object && o.constructor === Object),
'Expecting an object'
);

Expand Down
5 changes: 5 additions & 0 deletions testData/invalid/yaml/null_value.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Resources:
MyBucket:
Type: 'AWS::S3::Bucket'
Properties:
Tags: null