Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve whitespaces in single-quote literal fallback #5775

Merged
merged 2 commits into from
Feb 3, 2019
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
2 changes: 1 addition & 1 deletion lib/classes/Variables.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Variables {
this.variableSyntax, this.variableSyntax,
(context, contents) => contents.trim() (context, contents) => contents.trim()
); );
if (!cleaned.match(/".*"/)) { if (!cleaned.match(/".*"|'.*'/)) {
cleaned = cleaned.replace(/\s/g, ''); cleaned = cleaned.replace(/\s/g, '');
} }
return cleaned; return cleaned;
Expand Down
12 changes: 11 additions & 1 deletion lib/classes/Variables.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ describe('Variables', () => {
return serverless.variables.populateObject(service.custom) return serverless.variables.populateObject(service.custom)
.should.become(expected); .should.become(expected);
}); });
it('should preserve whitespace in literal fallback', () => { it('should preserve whitespace in double-quote literal fallback', () => {
service.custom = { service.custom = {
val0: '${self:custom.val, "rate(3 hours)"}', val0: '${self:custom.val, "rate(3 hours)"}',
}; };
Expand All @@ -796,6 +796,16 @@ describe('Variables', () => {
return serverless.variables.populateObject(service.custom) return serverless.variables.populateObject(service.custom)
.should.become(expected); .should.become(expected);
}); });
it('should preserve whitespace in single-quote literal fallback', () => {
service.custom = {
val0: '${self:custom.val, \'rate(1 hour)\'}',
};
const expected = {
val0: 'rate(1 hour)',
};
return serverless.variables.populateObject(service.custom)
.should.become(expected);
});
it('should accept whitespace in variables', () => { it('should accept whitespace in variables', () => {
service.custom = { service.custom = {
val0: '${self: custom.val}', val0: '${self: custom.val}',
Expand Down