:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(cdp): send push notification text without html escaping (#122966)
Daniel Marchuk16483367671a
diff --git a/nodejs/src/cdp/services/hog-inputs.service.test.ts b/nodejs/src/cdp/services/hog-inputs.service.test.tsindex 60f583711cca..eda5d61c29c6 100644--- a/nodejs/src/cdp/services/hog-inputs.service.test.ts+++ b/nodejs/src/cdp/services/hog-inputs.service.test.ts@@ -11,6 +11,7 @@ import { createHogExecutionGlobals, createHogFunction, insertIntegration } fromimport { compileHog } from '../templates/compiler'import { HogFunctionInvocationGlobals, HogFunctionType } from '../types'import { classifyHogError } from '../utils/hog-error-classification'+import { NATIVE_PUSH_TEMPLATE_ID } from '../utils/push-subscription-utils'import { HogInputsService, formatHogInput, formatLiquidInput, getAppIdentifierForPush } from './hog-inputs.service'import { RecipientTokensService } from './messaging/recipient-tokens.service'@@ -413,6 +414,25 @@ describe('Hog Inputs', () => {})})+ it('renders liquid in push notification inputs without html escaping', async () => {+ globals.event.properties.feature = `Logs & "Traces" <beta>`+ hogFunction.template_id = NATIVE_PUSH_TEMPLATE_ID+ hogFunction.inputs = {+ title: { templating: 'liquid', value: 'Try {{ event.properties.feature }}' },+ body: { templating: 'liquid', value: '{{ event.properties.feature }}' },+ data: { templating: 'liquid', value: { url: 'myapp://{{ event.properties.feature }}' } },+ }+ hogFunction.inputs_schema = [+ { key: 'title', type: 'string', required: true },+ { key: 'body', type: 'string', templating: 'liquid' },+ { key: 'data', type: 'dictionary' },+ ]++ const inputs = await hogInputsService.buildInputs(hogFunction, globals)+ const raw = `Logs & "Traces" <beta>`+ expect(inputs).toMatchObject({ title: `Try ${raw}`, body: raw, data: { url: `myapp://${raw}` } })+ })+it('drops the editor design from a liquid email instead of rendering it', async () => {const tag = '{% if event.event == "test" %}Hi{% endif %}'hogFunction.inputs = {diff --git a/nodejs/src/cdp/services/hog-inputs.service.ts b/nodejs/src/cdp/services/hog-inputs.service.tsindex b8a0faa0107d..5d9867675933 100644--- a/nodejs/src/cdp/services/hog-inputs.service.ts+++ b/nodejs/src/cdp/services/hog-inputs.service.ts@@ -9,7 +9,7 @@ import { EncryptedFields } from '../utils/encryption-utils'import { HogConfigurationError, isHogVMErrorKind, withBytecodeContract } from '../utils/hog-error-classification'import { execHog } from '../utils/hog-exec'import { LiquidRenderBudget, LiquidRenderer } from '../utils/liquid'-import { getDevicePushSubscriptionToken } from '../utils/push-subscription-utils'+import { NATIVE_PUSH_TEMPLATE_ID, getDevicePushSubscriptionToken } from '../utils/push-subscription-utils'import { IntegrationManagerService } from './managers/integration-manager.service'import { RecipientTokensService } from './messaging/recipient-tokens.service'@@ -87,9 +87,12 @@ export class HogInputsService {const { design: _design, ...rest } = valuevalue = rest}+ // A device shows push text literally, so an HTML entity would reach the person as written.const plainTextKeys = EMAIL_INPUT_TYPES.includes(schemaTypes[key])? new Set(EMAIL_PLAIN_TEXT_FIELDS.map((field) => `${key}.${field}`))- : undefined+ : hogFunction.template_id === NATIVE_PUSH_TEMPLATE_ID+ ? new Set([key])+ : undefinedreturn formatLiquidInput(value, newGlobals, key, liquidBudget, plainTextKeys)}if (templating === 'hog' && input?.bytecode) {@@ -380,6 +383,19 @@ const liquidErrorKind = (error: unknown): HogVMErrorKind => {return 'contract'}+// A key is plain text when it or any object it sits in is listed, such as `data.url` under `data`.+const isPlainTextKey = (key: string | undefined, plainTextKeys: ReadonlySet<string> | undefined): boolean => {+ let current = key+ while (current && plainTextKeys) {+ if (plainTextKeys.has(current)) {+ return true+ }+ const dot = current.lastIndexOf('.')+ current = dot === -1 ? undefined : current.slice(0, dot)+ }+ return false+}+export const formatLiquidInput = (value: unknown,globals: HogFunctionInvocationGlobalsWithInputs,@@ -394,7 +410,7 @@ export const formatLiquidInput = (if (typeof value === 'string') {try {return LiquidRenderer.renderWithHogFunctionGlobals(value, globals, budget, {- escapeHtml: !(key && plainTextKeys?.has(key)),+ escapeHtml: !isPlainTextKey(key, plainTextKeys),})} catch (error) {// The renderer's message names the template line the owner has to fix, so it stays as is.