Skip to content

Modern Docker Management, Designed for Everyone

fix: allow yaml merge syntax (#2033)

Kyle Mendellc55e45420ae6
diff --git a/frontend/src/lib/components/code-editor/analysis/compose-analysis.ts b/frontend/src/lib/components/code-editor/analysis/compose-analysis.ts
index dce5127a7..28bfb44d2 100644
--- a/frontend/src/lib/components/code-editor/analysis/compose-analysis.ts
+++ b/frontend/src/lib/components/code-editor/analysis/compose-analysis.ts
@@ -143,7 +143,7 @@ function findContextInNode(
}
export function findYamlPositionContext(source: string, position: number): YamlPositionContext | null {
- const doc = parseDocument(source, { strict: true, uniqueKeys: false });
+ const doc = parseDocument(source, { strict: true, uniqueKeys: false, merge: true });
return findContextInNode((doc.contents as ParsedNode | null) ?? null, position, []);
}
@@ -171,7 +171,7 @@ function findKeyRangeInSource(source: string, key: string): { from: number; to:
};
}
-function toSchemaDiagnostic(error: ErrorObject, doc: YamlDocLike, source: string): Diagnostic {
+function toSchemaDiagnostic(error: ErrorObject, doc: YamlDocLike, source: string): Diagnostic | null {
const path = pointerToPath(error.instancePath || '');
const params = error.params as Record<string, unknown>;
const missingProperty = typeof params.missingProperty === 'string' ? params.missingProperty : null;
@@ -189,6 +189,7 @@ function toSchemaDiagnostic(error: ErrorObject, doc: YamlDocLike, source: string
message = `Missing required property "${missingProperty}"`;
}
if (error.keyword === 'additionalProperties' && additionalProperty) {
+ if (additionalProperty === '<<') return null;
message = `Unsupported property "${additionalProperty}"`;
}
@@ -211,7 +212,7 @@ function collectDuplicateKeyDiagnostics(node: ParsedNode | null | undefined, dia
const key = scalarToKey(item.key);
if (key) {
const keyRange = getRange(item.key);
- if (seen.has(key)) {
+ if (seen.has(key) && key !== '<<') {
duplicateCount += 1;
diagnostics.push({
from: keyRange?.[0] ?? 0,
@@ -473,7 +474,8 @@ export async function analyzeComposeContent(
const doc = parseDocument(source, {
lineCounter,
strict: true,
- uniqueKeys: false
+ uniqueKeys: false,
+ merge: true
}) as unknown as YamlDocLike;
const diagnostics: Diagnostic[] = [];
@@ -505,7 +507,8 @@ export async function analyzeComposeContent(
const isValid = schemaContext.validate(parsedValue);
if (!isValid) {
for (const error of (schemaContext.validate.errors || []).slice(0, maxSchemaDiagnostics)) {
- diagnostics.push(toSchemaDiagnostic(error, doc, source));
+ const diag = toSchemaDiagnostic(error, doc, source);
+ if (diag) diagnostics.push(diag);
}
}
}
diff --git a/frontend/src/lib/components/code-editor/analysis/env-analysis.ts b/frontend/src/lib/components/code-editor/analysis/env-analysis.ts
index 0a9ff0b8a..9557d652f 100644
--- a/frontend/src/lib/components/code-editor/analysis/env-analysis.ts
+++ b/frontend/src/lib/components/code-editor/analysis/env-analysis.ts
@@ -1,6 +1,7 @@
import type { EditorView } from '@codemirror/view';
import type { Diagnostic } from '@codemirror/lint';
import type { AnalysisResult, EditorContext, OutlineItem } from './types';
+import { isOpenQuote } from './parse-env-utils';
import { extractComposeVariables } from './vars-analysis';
const ENV_KEY_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;
@@ -32,6 +33,70 @@ function parseEnv(source: string): {
const lines = source.split('\n');
let offset = 0;
+ let multiLineKey: string | null = null;
+ let multiLineQuote: string | null = null;
+ let multiLineFrom = 0;
+ let multiLineTo = 0;
+ let multiLineKeyFrom = 0;
+ let multiLineKeyTo = 0;
+ let multiLineLineNumber = 0;
+ let multiLineParts: string[] = [];
+
+ function finalizeEntry(
+ key: string,
+ value: string,
+ lineNumber: number,
+ from: number,
+ to: number,
+ keyFrom: number,
+ keyTo: number
+ ): void {
+ const parsed: ParsedEnvLine = { lineNumber, from, to: Math.max(from + 1, to), key, value, keyFrom, keyTo };
+
+ if (seen.has(key)) {
+ const previous = seen.get(key);
+ duplicateKeys += 1;
+ diagnostics.push({
+ from: keyFrom,
+ to: keyTo,
+ severity: 'warning',
+ message: `Duplicate variable "${key}". Last value wins.`,
+ actions: [
+ {
+ name: 'Remove earlier duplicate',
+ apply(view: EditorView) {
+ const doc = view.state.doc;
+ const target = previous ?? parsed;
+ let removeTo = target.to;
+ const nextChars = doc.sliceString(removeTo, Math.min(doc.length, removeTo + 2));
+ if (nextChars.startsWith('\r\n')) {
+ removeTo += 2;
+ } else if (nextChars.startsWith('\n')) {
+ removeTo += 1;
+ }
+ view.dispatch({
+ changes: { from: target.from, to: removeTo, insert: '' }
+ });
+ }
+ }
+ ]
+ });
+ }
+
+ seen.set(key, parsed);
+ entries.push(parsed);
+
+ if (SECRET_NAME_REGEX.test(key) || SECRET_VALUE_REGEX.test(value)) {
+ secretWarnings += 1;
+ diagnostics.push({
+ from: keyFrom,
+ to: keyTo,
+ severity: 'warning',
+ message: `"${key}" looks like a secret. Consider using Docker secrets or external secret management.`
+ });
+ }
+ }
+
for (let index = 0; index < lines.length; index += 1) {
const rawLine = lines[index] ?? '';
const line = rawLine.endsWith('\r') ? rawLine.slice(0, -1) : rawLine;
@@ -41,6 +106,23 @@ function parseEnv(source: string): {
offset += rawLine.length + 1;
+ // Inside a multi-line quoted value — accumulate until closing quote
+ if (multiLineQuote !== null && multiLineKey !== null) {
+ multiLineParts.push(rawLine.endsWith('\r') ? rawLine.slice(0, -1) : rawLine);
+ multiLineTo = lineTo;
+
+ const trimmedEnd = line.trimEnd();
+ const isEscaped = trimmedEnd.length >= 2 && trimmedEnd[trimmedEnd.length - 2] === '\\';
+ if (trimmedEnd.endsWith(multiLineQuote) && !isEscaped) {
+ const fullValue = multiLineParts.join('\n');
+ finalizeEntry(multiLineKey, fullValue, multiLineLineNumber, multiLineFrom, multiLineTo, multiLineKeyFrom, multiLineKeyTo);
+ multiLineKey = null;
+ multiLineQuote = null;
+ multiLineParts = [];
+ }
+ continue;
+ }
+
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
@@ -73,54 +155,31 @@ function parseEnv(source: string): {
continue;
}
- const parsed: ParsedEnvLine = {
- lineNumber,
- from: lineFrom,
- to: Math.max(lineFrom + 1, lineTo),
- key,
- value,
- keyFrom,
- keyTo
- };
-
- if (seen.has(key)) {
- const previous = seen.get(key);
- duplicateKeys += 1;
- diagnostics.push({
- from: keyFrom,
- to: keyTo,
- severity: 'warning',
- message: `Duplicate variable "${key}". Last value wins.`,
- actions: [
- {
- name: 'Remove earlier duplicate',
- apply(view: EditorView) {
- const doc = view.state.doc;
- const targetLineNumber = previous?.lineNumber ?? lineNumber;
- if (targetLineNumber < 1 || targetLineNumber > doc.lines) return;
- const lineInfo = doc.line(targetLineNumber);
- const removeTo = lineInfo.number < doc.lines ? doc.line(targetLineNumber + 1).from : lineInfo.to;
- view.dispatch({
- changes: { from: lineInfo.from, to: removeTo, insert: '' }
- });
- }
- }
- ]
- });
+ // Check for multi-line quoted value
+ const openQuote = isOpenQuote(value);
+ if (openQuote) {
+ multiLineKey = key;
+ multiLineQuote = openQuote;
+ multiLineFrom = lineFrom;
+ multiLineTo = lineTo;
+ multiLineKeyFrom = keyFrom;
+ multiLineKeyTo = keyTo;
+ multiLineLineNumber = lineNumber;
+ multiLineParts = [value];
+ continue;
}
- seen.set(key, parsed);
- entries.push(parsed);
+ finalizeEntry(key, value, lineNumber, lineFrom, lineTo, keyFrom, keyTo);
+ }
- if (SECRET_NAME_REGEX.test(key) || SECRET_VALUE_REGEX.test(value)) {
- secretWarnings += 1;
- diagnostics.push({
- from: keyFrom,
- to: keyTo,
- severity: 'warning',
- message: `"${key}" looks like a secret. Consider using Docker secrets or external secret management.`
- });
- }
+ // Unterminated multi-line quoted value at EOF
+ if (multiLineQuote !== null && multiLineKey !== null) {
+ diagnostics.push({
+ from: multiLineFrom,
+ to: Math.max(multiLineFrom + 1, multiLineTo),
+ severity: 'error',
+ message: `Unterminated quoted value for "${multiLineKey}". Missing closing ${multiLineQuote}.`
+ });
}
return { entries, diagnostics, duplicateKeys, secretWarnings };
diff --git a/frontend/src/lib/components/code-editor/analysis/parse-env-utils.ts b/frontend/src/lib/components/code-editor/analysis/parse-env-utils.ts
new file mode 100644
index 000000000..367f575eb
--- /dev/null
+++ b/frontend/src/lib/components/code-editor/analysis/parse-env-utils.ts
@@ -0,0 +1,10 @@
+export function isOpenQuote(value: string): string | null {
+ // Simplification: this only detects obviously unterminated leading quotes.
+ // Values that start/end with the same quote are treated as closed, even if
+ // their internal quoting would be malformed in a stricter parser.
+ if (value.length === 0) return null;
+ const quote = value[0];
+ if (quote !== '"' && quote !== "'") return null;
+ if (value.length >= 2 && value[value.length - 1] === quote) return null;
+ return quote;
+}
diff --git a/frontend/src/lib/components/code-editor/analysis/vars-analysis.ts b/frontend/src/lib/components/code-editor/analysis/vars-analysis.ts
index 99d9d228f..05476ee42 100644
--- a/frontend/src/lib/components/code-editor/analysis/vars-analysis.ts
+++ b/frontend/src/lib/components/code-editor/analysis/vars-analysis.ts
@@ -1,4 +1,5 @@
import type { EditorContext } from './types';
+import { isOpenQuote } from './parse-env-utils';
const BRACED_VAR_REGEX = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?:(?::[-?+])[^}]*)?\}/g;
const SIMPLE_VAR_REGEX = /(^|[^$])\$([A-Za-z_][A-Za-z0-9_]*)/g;
@@ -26,7 +27,25 @@ export function parseEnvVariables(envContent: string): Map<string, string> {
const values = new Map<string, string>();
const lines = envContent.split(/\r?\n/);
+ let multiLineKey: string | null = null;
+ let multiLineQuote: string | null = null;
+ let multiLineParts: string[] = [];
+
for (const rawLine of lines) {
+ // Inside a multi-line quoted value — accumulate until closing quote
+ if (multiLineQuote !== null && multiLineKey !== null) {
+ multiLineParts.push(rawLine);
+ const trimmedEnd = rawLine.trimEnd();
+ const isEscaped = trimmedEnd.length >= 2 && trimmedEnd[trimmedEnd.length - 2] === '\\';
+ if (trimmedEnd.endsWith(multiLineQuote) && !isEscaped) {
+ values.set(multiLineKey, multiLineParts.join('\n'));
+ multiLineKey = null;
+ multiLineQuote = null;
+ multiLineParts = [];
+ }
+ continue;
+ }
+
const trimmed = rawLine.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
@@ -38,9 +57,22 @@ export function parseEnvVariables(envContent: string): Map<string, string> {
if (!ENV_KEY_REGEX.test(key)) continue;
const value = line.slice(separator + 1).trim();
+
+ const openQuote = isOpenQuote(value);
+ if (openQuote) {
+ multiLineKey = key;
+ multiLineQuote = openQuote;
+ multiLineParts = [value];
+ continue;
+ }
+
values.set(key, value);
}
+ if (multiLineKey !== null && multiLineParts.length > 0) {
+ values.set(multiLineKey, multiLineParts.join('\n'));
+ }
+
return values;
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 123e66d36..41f76c0fc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -2789,7 +2789,6 @@ packages:
resolution: {integrity: sha512-vuNwKSaKiqm7g0THUBu2x7ckSs3XJLXE+2ssL7/MfTGPLLcrJQ/4Uq1CjPTtO5cCIiRxqvN6Twy1qOwhL0Xjcw==}
engines: {node: 20 || >=22}
- deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting [email protected]
hasBin: true