Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code cfd5d5f537 fix: coerce defaultValue to string in getInitialEditorContent to prevent split crash
https://sonarly.com/issue/21236?type=bug

When a workflow action's settings contain a non-string value (e.g., number, boolean, or object) for a field rendered as text, `getInitialEditorContent` crashes because `.split()` is called on a non-string value.
2026-04-02 14:40:29 +00:00
2 changed files with 60 additions and 1 deletions
@@ -301,6 +301,65 @@ describe('getInitialEditorContent', () => {
],
"type": "doc",
}
`);
});
it('should coerce non-string values to string without throwing', () => {
expect(
getInitialEditorContent(42 as unknown as string),
).toMatchInlineSnapshot(`
{
"content": [
{
"content": [
{
"text": "42",
"type": "text",
},
],
"type": "paragraph",
},
],
"type": "doc",
}
`);
expect(
getInitialEditorContent(true as unknown as string),
).toMatchInlineSnapshot(`
{
"content": [
{
"content": [
{
"text": "true",
"type": "text",
},
],
"type": "paragraph",
},
],
"type": "doc",
}
`);
expect(
getInitialEditorContent({ key: 'value' } as unknown as string),
).toMatchInlineSnapshot(`
{
"content": [
{
"content": [
{
"text": "[object Object]",
"type": "text",
},
],
"type": "paragraph",
},
],
"type": "doc",
}
`);
});
});
@@ -6,7 +6,7 @@ export const CAPTURE_VARIABLE_TAG_REGEX = /({{[^{}]+}})/;
export const getInitialEditorContent = (rawContent: string): JSONContent => {
const paragraphContent: JSONContent[] = [];
const lines = rawContent.split(/\n/);
const lines = String(rawContent).split(/\n/);
lines.forEach((line, index) => {
const parts = line.split(CAPTURE_VARIABLE_TAG_REGEX);