Skip to content

Commit 09f55a2

Browse files
authored
html escaping (#53)
1 parent b7bf59b commit 09f55a2

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

packages/object-transform/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curatedotfun/object-transform",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Object transformation plugin for curatedotfun with configurable field mappings",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

packages/object-transform/src/__tests__/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,22 @@ describe("ObjectTransformer", () => {
367367
});
368368
});
369369
});
370+
371+
it("should not HTML-encode link fields", async () => {
372+
await transformer.initialize({
373+
mappings: {
374+
link: "{{url}}",
375+
},
376+
});
377+
378+
const result = await transformer.transform({
379+
input: {
380+
url: "https://example.com/some/path?query=string",
381+
},
382+
});
383+
384+
expect(result).toEqual({
385+
link: "https://example.com/some/path?query=string",
386+
});
387+
});
370388
});

packages/object-transform/src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import { z } from "zod";
33
import { format } from "date-fns";
44
import type { TransformerPlugin, ActionArgs } from "@curatedotfun/types";
55

6-
// Create a local copy of Mustache with custom settings
7-
const localMustache = { ...Mustache };
8-
localMustache.escape = function (text) {
9-
return text;
10-
};
11-
126
// Default template generators
137
type TemplateGenerator = (formatStr?: string) => string | number;
148

@@ -83,7 +77,10 @@ export default class ObjectTransformer
8377
): unknown => {
8478
// Helper function to process template value
8579
const processTemplate = (template: string) => {
86-
const rendered = localMustache.render(template, inputData);
80+
const originalEscape = Mustache.escape;
81+
Mustache.escape = (text) => text;
82+
const rendered = Mustache.render(template, inputData);
83+
Mustache.escape = originalEscape;
8784

8885
// If the template references a field that's an array or object, return it directly
8986
const fieldMatch = template.match(/^\{\{([^}]+)\}\}$/);

packages/simple-transform/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curatedotfun/simple-transform",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "Simple transform plugin for curatedotfun",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

packages/simple-transform/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Mustache from "mustache";
22
import type { TransformerPlugin, ActionArgs } from "@curatedotfun/types";
33

4-
const localMustache = { ...Mustache };
5-
64
interface SimpleTransformerConfig extends Record<string, unknown> {
75
template: string;
86
}
@@ -23,7 +21,7 @@ export default class SimpleTransformer
2321
input,
2422
}: ActionArgs<unknown, SimpleTransformerConfig>): Promise<string> {
2523
try {
26-
return localMustache.render(this.template, input);
24+
return Mustache.render(this.template, input);
2725
} catch (error: unknown) {
2826
const errorMessage =
2927
error instanceof Error ? error.message : "Unknown error occurred";

0 commit comments

Comments
 (0)