Skip to content

armgit / cogit

Public Imported from GitHub
0

Git for the intent behind agent-written code. Records what your coding agent decided and why, and links every commit to it.

fix(build): embed the record so a $' in it cannot break the page

Eren083141d1455f
diff --git a/packages/cli/src/view/lineage.ts b/packages/cli/src/view/lineage.ts
index 5ca7e42..c361219 100644
--- a/packages/cli/src/view/lineage.ts
+++ b/packages/cli/src/view/lineage.ts
@@ -386,5 +386,6 @@ export function embedViewModel(template: string, model: PageModel): string {
const data = `<script id="${DATA_ELEMENT_ID}" type="application/json">${escapeForScript(
JSON.stringify(model),
)}</script>`;
- return template.replace(EMPTY_DATA_ELEMENT, data);
+ // A function, not a string: a `$'` or `$&` in the data must not act as a replace pattern.
+ return template.replace(EMPTY_DATA_ELEMENT, () => data);
}
diff --git a/packages/cli/test/build.test.ts b/packages/cli/test/build.test.ts
index 70ab8ed..5d80283 100644
--- a/packages/cli/test/build.test.ts
+++ b/packages/cli/test/build.test.ts
@@ -434,6 +434,11 @@ describe("embedViewModel", () => {
expect(embedded(html)).toEqual(risky);
});
+ it("keeps a `$'` or `$&` in the data as text, not as a replace pattern", () => {
+ const priced = { ...model, project: { ...model.project, name: "under 0,02 $'s budget $& $`" } };
+ expect(embedded(embedViewModel(TEMPLATE, priced))).toEqual(priced);
+ });
+
it("refuses a template without the data element", () => {
expect(() => embedViewModel("<html></html>", model)).toThrow(/no empty/);
});