diff --git a/src/server/lib/nativeHelm/__tests__/helm.test.ts b/src/server/lib/nativeHelm/__tests__/helm.test.ts index eb069be..4f89f6a 100644 --- a/src/server/lib/nativeHelm/__tests__/helm.test.ts +++ b/src/server/lib/nativeHelm/__tests__/helm.test.ts @@ -483,6 +483,38 @@ describe('Native Helm', () => { expect(result).not.toContain('--version'); }); + it('should preserve inner double quotes in --set keys for annotation paths', () => { + const result = constructHelmCommand( + 'upgrade --install', + 'my-chart', + 'my-release', + 'my-namespace', + ['ingress.extraAnnotations."app\\.kubernetes\\.io/name"=my-app'], + [], + ChartType.PUBLIC, + undefined, + 'https://example.com/charts' + ); + + expect(result).toContain('--set "ingress.extraAnnotations.\\"app\\.kubernetes\\.io/name\\"=my-app"'); + }); + + it('should escape inner double quotes in --set values', () => { + const result = constructHelmCommand( + 'upgrade --install', + 'my-chart', + 'my-release', + 'my-namespace', + ['deployment.env.MSG="hello world"'], + [], + ChartType.PUBLIC, + undefined, + 'https://example.com/charts' + ); + + expect(result).toContain('--set "deployment.env.MSG=\\"hello world\\""'); + }); + it('should not add chart version for PUBLIC charts when version is not specified', () => { const result = constructHelmCommand( 'upgrade --install', diff --git a/src/server/lib/nativeHelm/utils.ts b/src/server/lib/nativeHelm/utils.ts index 7ea2de1..d722c68 100644 --- a/src/server/lib/nativeHelm/utils.ts +++ b/src/server/lib/nativeHelm/utils.ts @@ -93,12 +93,12 @@ export function constructHelmCommand( customValues.forEach((value) => { const equalIndex = value.indexOf('='); if (equalIndex > -1) { - const key = value.substring(0, equalIndex); + const key = value.substring(0, equalIndex).replace(/"/g, '\\"'); const val = value.substring(equalIndex + 1); - const escapedVal = escapeHelmValue(val); + const escapedVal = escapeHelmValue(val).replace(/"/g, '\\"'); command += ` --set "${key}=${escapedVal}"`; } else { - command += ` --set "${value}"`; + command += ` --set "${value.replace(/"/g, '\\"')}"`; } });