Skip to content

fix: improve YAML stringification for tabbed values #1573

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

Merged
merged 1 commit into from
May 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions source/javascripts/core/api/BitriseYmlApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse, stringify } from 'yaml';
import { parse, Scalar, stringify } from 'yaml';

import { BitriseYml } from '@/core/models/BitriseYml';
import RuntimeUtils from '@/core/utils/RuntimeUtils';
Expand All @@ -8,6 +8,21 @@ import Client from './client';
const CI_CONFIG_VERSION_HEADER = 'Bitrise-Config-Version';

// TRANSFORMATIONS

// NOTE: When the value is a string and contains a tab characters, the eemeli/yaml
// will stringify it as multi-line block string, but keep the tab characters. It's not optimal
// for us, because it's not a valid YAML for the Bitrise CLI. So we need to keep the single
// line string with double quotes. This is a workaround for the issue.
function tabbedValueReplacer(_: unknown, value: unknown) {
if (typeof value === 'string' && /\t/.test(value)) {
const scalar = new Scalar(value);
scalar.type = 'QUOTE_DOUBLE';
return scalar;
}

return value;
}

function toYml(model?: unknown): string {
if (!model) {
return '';
Expand All @@ -17,7 +32,7 @@ function toYml(model?: unknown): string {
return model;
}

return stringify(model, {
return stringify(model, tabbedValueReplacer, {
version: '1.1',
indentSeq: false,
schema: 'yaml-1.1',
Expand Down