Skip to content

fix(core): escape periods in attribute keys during flatten/unflatten (#1510)#3857

Closed
deepshekhardas wants to merge 1 commit into
triggerdotdev:mainfrom
deepshekhardas:fix/1510-period-keys-attribute-flattening
Closed

fix(core): escape periods in attribute keys during flatten/unflatten (#1510)#3857
deepshekhardas wants to merge 1 commit into
triggerdotdev:mainfrom
deepshekhardas:fix/1510-period-keys-attribute-flattening

Conversation

@deepshekhardas
Copy link
Copy Markdown

Fixes #1510

Object keys containing periods (e.g. { "Key 0.002mm": 31.4 }) were incorrectly split on the . delimiter during flattening, causing dashboard display corruption.

Fix: Escape . in object keys with $@dot sentinel during flatten and unescape during unflatten. This is consistent with the existing $@null(( and $@circular(( sentinel pattern.

Changes:

  • flattenAttributes.ts: escape dots in non-array keys during flatten
  • unflattenAttributes(): unescape sentinel back to . after splitting
  • Added 3 test cases for period-containing keys

Object keys containing periods (e.g. 'Key 0.002mm') were incorrectly
split on the '.' delimiter during flatten/unflatten, causing data
corruption in the dashboard logs view. Escape dots with \$@dot sentinel
during flattening and unescape during unflattening.

Fixes triggerdotdev#1510
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 7, 2026

⚠️ No Changeset found

Latest commit: f515902

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 7, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8d0900c2-5852-4ce9-a112-e9cea2e21892

📥 Commits

Reviewing files that changed from the base of the PR and between 97036fb and f515902.

📒 Files selected for processing (2)
  • packages/core/src/v3/utils/flattenAttributes.ts
  • packages/core/test/flattenAttributes.test.ts

Walkthrough

This PR adds dot-character escaping to the flattenAttributes and unflattenAttributes utility functions. A new internal constant DOT_ESCAPE marks escaped periods in flattened keys. The flatten function now escapes . characters in property names using this marker during prefix construction, while the unflatten function reverses the process by unescaping those markers before parsing bracket-indexed array segments. Test cases verify that keys containing single or multiple periods are correctly escaped, nested properly with prefixes, and fully recover their original form when unflattened.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

Hi @deepshekhardas, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this Jun 7, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Map keys with dots are NOT escaped — inconsistency with object key escaping

The PR escapes dots in regular object keys at line 204, but Map keys at packages/core/src/v3/utils/flattenAttributes.ts:120-121 are used directly without dot escaping: this.#processValue(value, \${prefix || "map"}.${keyStr}`, depth)`. This means Map keys containing dots will still be incorrectly split during unflattening, just as they were before this PR. While Maps can't be round-tripped anyway (they become plain objects during unflatten), this is an incomplete fix that could confuse developers who expect consistent behavior.

(Refers to lines 120-121)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

}

const newPrefix = `${prefix ? `${prefix}.` : ""}${Array.isArray(obj) ? `[${key}]` : key}`;
const escapedKey = Array.isArray(obj) ? `[${key}]` : key.replace(/\./g, DOT_ESCAPE);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Escape sentinel $@dot is not self-escaped, corrupting keys that naturally contain $@dot

The flattenAttributes function escapes dots in keys by replacing . with $@dot (line 204), but does NOT first escape any pre-existing $@dot substrings. During unflattenAttributes, ALL occurrences of $@dot are unconditionally unescaped back to . via part.split(DOT_ESCAPE).join(".") at line 285. This means a key that naturally contains $@dot (e.g., {"x$@doty": 1}) will be corrupted on round-trip: flattenAttributes leaves it as "x$@doty" (no dots to replace), but unflattenAttributes converts it to "x.y", splitting it into a nested structure {x: {y: 1}} instead of preserving the original key.

Reproduction example

flattenAttributes({"x$@DOty": 1}) → {"x$@DOty": 1}
unflattenAttributes({"x$@DOty": 1}) → {x: {y: 1}} // Should be {"x$@DOty": 1}

Prompt for agents
The DOT_ESCAPE sentinel ($@dot) used to escape dots in object keys is not itself escaped, causing a sentinel collision for keys that naturally contain the substring $@dot. To fix this, flattenAttributes (line 204 in flattenAttributes.ts) needs to first escape any pre-existing DOT_ESCAPE occurrences before replacing dots. For example, you could introduce a secondary escape like $@esc that replaces $@ with $@esc in the key first, then replace . with $@dot. In unflattenAttributes (line 285), reverse the process: first replace $@dot with ., then replace $@esc with $@. This ensures that keys containing $@dot are preserved through the round-trip. Alternatively, choose an escape token that is guaranteed not to collide (though this is difficult in general), or use a different encoding scheme entirely (e.g., percent-encoding dots as %2E).
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


export const NULL_SENTINEL = "$@null((";
export const CIRCULAR_REFERENCE_SENTINEL = "$@circular((";
const DOT_ESCAPE = "$@dot";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Cross-version SDK/webapp compatibility considerations

This is a @trigger.dev/core change (a published package) that affects both the SDK running in customer containers and the webapp. If the webapp is upgraded first (likely in the hosted service), old SDK versions will continue sending unescaped keys — this is safe since the new unflatten is backward compatible. If a customer upgrades their SDK first while running an older self-hosted webapp, the escaped $@dot in keys would appear as literal text in the old webapp's unflatten output. This is an acceptable trade-off but worth noting for self-hosted users. The PR does not include a changeset, which is required per CONTRIBUTING.md for changes to packages in /packages.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TRI-4123] Logging objects with keys with periods in doesn't render properly in the UI

1 participant