Skip to content

Commit

Permalink
workaround CloudFormation bug re non-octal strings with leading 0s
Browse files Browse the repository at this point in the history
  • Loading branch information
tavisrudd committed Feb 6, 2018
1 parent 5dcce1a commit eeab864
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/preprocess/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,23 @@ const visitArray = (node: AnyButUndefined[], path: string, env: Env): AnyButUnde
_.map(node, (v, i) => visitNode(v, appendPath(path, i.toString()), env));

export function visitString(node: string, path: string, env: Env): string {
let res: string;
if (node.search(HANDLEBARS_RE) > -1) {
return interpolateHandlebarsString(node, env.$envValues, path);
res = interpolateHandlebarsString(node, env.$envValues, path);
} else {
return node;
res = node;
}
if (res.match(/^(0\d+)$/)) {
// this encoding works around non-octal numbers with leading 0s
// not being quoted by jsyaml.dump which then causes issues with
// CloudFormation mis-parsing those as octal numbers. The encoding
// is removed in ../yaml.ts:dump

// js-yaml devs don't want to change the behaviour so we need this
// workaround https://github.com/nodeca/js-yaml/issues/394
res = `$0string ${res}`;
}
return res;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 3 additions & 1 deletion src/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,6 @@ export const loadString = (content: string | Buffer, filename: string): any =>
export const dump = (doc: object): string =>
jsyaml.safeDump(doc, {schema: schema, lineWidth: 999})
.replace(/!<!([^>]+?)>/g, '!$1')
.replace(/ !\$include /g, ' !$ ');
.replace(/ !\$include /g, ' !$ ')
.replace(/\$0string \s*(0\d+)/g, "'$1'");
// $0string ^ is an encoding added in preprocess/index.ts:visitString

0 comments on commit eeab864

Please sign in to comment.