Repository: awslabs/cdk8s (ts)

Issue:
Octal numbers are not parsed correctly when including manifests (or helm charts)
### Description of the bug:
<!--description of the bug:-->

See https://github.com/eemeli/yaml/issues/205




### Reproduction Steps:
<!--minimal amount of code that causes the bug (if possible) or a reference:-->

Try to `Include` a manifest that includes an octal number:

```yaml
my_number: 0666
```

The expectation is that this will be represented as:

```json
{ "my_number": 438 }
```

But instead, it is represented as `666`, which is not correct.

Root cause is an issue in the YAML library we use: https://github.com/eemeli/yaml/issues/205



### Error Log:
<!--what is the error message you are seeing?-->




### Environment:


  - **Framework Version**:
  - **OS**:


### Other:
<!-- e.g. detailed explanation, stacktraces, related issues, suggestions on how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc -->




--- 

This is :bug: Bug Report


Pull request description:
fix(lib): fail to import octal numbers via include (and helm)
When parsing YAML, use yaml-1.1 instead of 1.2 in order to allow octal numbers in the form `0775` (instead of `0o755`, which is what 1.2 requires). See https://github.com/eemeli/yaml/issues/205.

Fixes #348

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*


Patch:
diff --git a/packages/cdk8s/.projenrc.js b/packages/cdk8s/.projenrc.js
index 79daece96..d146aaa5e 100644
--- a/packages/cdk8s/.projenrc.js
+++ b/packages/cdk8s/.projenrc.js
@@ -16,7 +16,7 @@ const project = new JsiiProject({
   dependencies: {
     "follow-redirects": Semver.caret("1.11.0"),
     "json-stable-stringify": Semver.caret("1.0.1"),
-    "yaml": Semver.caret("1.7.2"),
+    "yaml": Semver.pinned("2.0.0-1"),
   },
   bundledDependencies: [
     "yaml",
diff --git a/packages/cdk8s/src/yaml.ts b/packages/cdk8s/src/yaml.ts
index ef4ab6e89..e95b984c7 100644
--- a/packages/cdk8s/src/yaml.ts
+++ b/packages/cdk8s/src/yaml.ts
@@ -52,7 +52,10 @@ export class Yaml {
    */
   public static load(urlOrFile: string): any[] {
     const body = loadurl(urlOrFile);
-    const objects = YAML.parseAllDocuments(body);
+
+    // we need to use yaml-1.1 so that octal numbers in the form `0775` will be parsed
+    // correctly (see https://github.com/eemeli/yaml/issues/205)
+    const objects = YAML.parseAllDocuments(body, { schema: 'yaml-1.1' });
     const result = new Array<any>();
 
     for (const obj of objects.map(x => x.toJSON())) {


Test patch:
diff --git a/packages/cdk8s/test/yaml.test.ts b/packages/cdk8s/test/yaml.test.ts
index 5d594882d..0ec5526f7 100644
--- a/packages/cdk8s/test/yaml.test.ts
+++ b/packages/cdk8s/test/yaml.test.ts
@@ -1,5 +1,7 @@
 import { Yaml } from '../src/yaml';
 import * as fs from 'fs';
+import * as path from 'path';
+import * as os from 'os';
 
 describe('load', () => {
   test('from file', () => {
@@ -77,4 +79,12 @@ describe('save', () => {
     expect(fs.readFileSync(outputFile, 'utf-8')).toMatchSnapshot();
   });
 
-})
+});
+
+test('yaml 1.1 octal numbers are parsed correctly', () => {
+  const tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'cdk8s-'));
+  const filePath = path.join(tmpdir, 'temp.yaml');
+  fs.writeFileSync(filePath, 'foo: 0755');
+  
+  expect(Yaml.load(filePath)).toEqual([ { foo: 493 }]);
+});