Skip to content

Commit fc29665

Browse files
committed
fix: syntax of variables we support
1 parent ca3f955 commit fc29665

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

libs/journeys/ui/src/components/TextResponse/utils/getTextResponseValues/getTextResponseValues.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ describe('getTextResponseValues', () => {
6666
it('resolves values for embed variant', () => {
6767
const input: TextResponseStrings = {
6868
label: ' {{ name }} ',
69+
// incorrect syntax should return unresolved:
6970
placeholder: '{{ title: CTO }}',
71+
// incorrect syntax should return unresolved:
7072
hint: '{{ some: value }}'
7173
}
7274
const result = getTextResponseValues(input, fields, 'embed')
7375
expect(result.label).toBe(' Alice ')
74-
expect(result.placeholder).toBe('Child of God')
75-
expect(result.hint).toBe('Some Value')
76+
expect(result.placeholder).toBe('{{ title: CTO }}')
77+
expect(result.hint).toBe('{{ some: value }}')
7678
})
7779

7880
it('replaces custom fields within mixed strings and leaves non-custom-field text intact', () => {

libs/journeys/ui/src/libs/resolveJourneyCustomizationString/resolveJourneyCustomizationString.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,31 @@ describe('resolveJourneyCustomizationString', () => {
4242
)
4343
})
4444

45-
it('ignores inline value content and still resolves from fields (quoted)', () => {
45+
it('does not support inline values; leaves tokens with colon unchanged (quoted)', () => {
4646
expect(
4747
resolveJourneyCustomizationString("{{ name: 'Knee Sail' }}", fields)
48-
).toBe('Alice')
48+
).toBe("{{ name: 'Knee Sail' }}")
4949
expect(
5050
resolveJourneyCustomizationString(
5151
'{{ title: "Some Random Title" }}',
5252
fields
5353
)
54-
).toBe('Child of God')
54+
).toBe('{{ title: "Some Random Title" }}')
5555
})
5656

57-
it('ignores inline value content and still resolves from fields (unquoted)', () => {
57+
it('does not support inline values; leaves tokens with colon unchanged (unquoted)', () => {
5858
expect(resolveJourneyCustomizationString('{{ some: value }}', fields)).toBe(
59-
'Some Value'
59+
'{{ some: value }}'
6060
)
6161
})
6262

63-
it('replaces custom fields regardless of surrounding whitespace', () => {
63+
it('replaces key-only custom fields regardless of surrounding whitespace', () => {
6464
expect(resolveJourneyCustomizationString(' {{ name }} ', fields)).toBe(
6565
' Alice '
6666
)
6767
expect(
6868
resolveJourneyCustomizationString(' {{ title: Some Title }}', fields)
69-
).toBe(' Child of God')
69+
).toBe(' {{ title: Some Title }}')
7070
})
7171

7272
it('trims spaces around the key before lookup', () => {

libs/journeys/ui/src/libs/resolveJourneyCustomizationString/resolveJourneyCustomizationString.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { JourneyFields_journeyCustomizationFields as JourneyCustomizationField } from '../../libs/JourneyProvider/__generated__/JourneyFields'
22

33
/**
4-
* Resolves a string that may strictly equal a customization template of the form
5-
* "{{ key }}" or "{{ key: value }}" against provided journey customization fields.
6-
* - Requires the entire string (after trim) to match the pattern.
7-
* - If key is found, returns field.value ?? field.defaultValue.
8-
* - If no match, key not found, or no resolved value, returns the original input.
4+
* Resolves all occurrences of customization templates within a string.
5+
* Supports only the "{{ key }}" syntax (no inline value support).
6+
* - For each custom field: returns field.value ?? field.defaultValue if key exists; otherwise keeps the custom field.
7+
* - Multiple custom fields and repeated keys are supported in one pass.
98
*/
109
export function resolveJourneyCustomizationString(
1110
input: string | null,
1211
journeyCustomizationFields: JourneyCustomizationField[]
1312
): string | null {
1413
if (input == null) return null
1514

16-
const customFieldsPattern =
17-
/\{\{\s*([^:}]+)(?:\s*:\s*(?:(['"])([^'"]*)\2|([^}]*?)))?\s*\}\}/g
15+
const customFieldsPattern = /\{\{\s*([^:}]+)\s*\}\}/g
1816

1917
const replaced = input.replace(customFieldsPattern, (fullMatch, key) => {
2018
const trimmedKey = String(key).trim()

0 commit comments

Comments
 (0)