diff --git a/ui/src/shared/components/object-parser.test.ts b/ui/src/shared/components/object-parser.test.ts index f787f293d5ff..357f0e0caa41 100644 --- a/ui/src/shared/components/object-parser.test.ts +++ b/ui/src/shared/components/object-parser.test.ts @@ -1,6 +1,15 @@ import {exampleWorkflowTemplate} from '../examples'; import {parse, stringify} from './object-parser'; +describe('parse and stringify are inverses', () => { + it('handles creationTimestamp', () => { + const testWorkflowTemplate = exampleWorkflowTemplate('test'); + testWorkflowTemplate.metadata.creationTimestamp = '2024-11-17T06:56:52Z'; + expect(parse(stringify(testWorkflowTemplate, 'yaml'))).toEqual(testWorkflowTemplate); + expect(parse(stringify(testWorkflowTemplate, 'json'))).toEqual(testWorkflowTemplate); + }); +}); + describe('parse', () => { it('handles a valid JSON string', () => { expect(parse('{}')).toEqual({}); diff --git a/ui/src/shared/components/object-parser.ts b/ui/src/shared/components/object-parser.ts index 7b4800abf660..b39e0dd7b919 100644 --- a/ui/src/shared/components/object-parser.ts +++ b/ui/src/shared/components/object-parser.ts @@ -1,17 +1,16 @@ import YAML from 'yaml'; +// Default is YAML 1.2, but Kubernetes uses YAML 1.1, which leads to subtle bugs. +// See https://github.com/argoproj/argo-workflows/issues/12205#issuecomment-2111572189 +const yamlVersion = '1.1'; + export function parse(value: string): T { if (value.startsWith('{')) { return JSON.parse(value); } - return YAML.parse(value, { - // Default is YAML 1.2, but Kubernetes uses YAML 1.1, which leads to subtle bugs. - // See https://github.com/argoproj/argo-workflows/issues/12205#issuecomment-2111572189 - version: '1.1', - strict: false - }) as T; + return YAML.parse(value, {version: yamlVersion, strict: false}) as T; } export function stringify(value: T, type: string) { - return type === 'yaml' ? YAML.stringify(value, {aliasDuplicateObjects: false}) : JSON.stringify(value, null, ' '); + return type === 'yaml' ? YAML.stringify(value, {aliasDuplicateObjects: false, version: yamlVersion, strict: false}) : JSON.stringify(value, null, ' '); }