fix(core): escape dots in object keys when flattening to prevent path collision - #4374
fix(core): escape dots in object keys when flattening to prevent path collision#4374okxint wants to merge 1 commit into
Conversation
|
|
Hi @okxint, 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. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughUpdated attribute flattening to escape dots in string keys from Maps and objects. Added parsing that splits only on unescaped dots and restores literal dots during unflattening. Added tests covering simple and nested dotted object keys. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Problem
Object keys that contain literal dots are misinterpreted as path separators when logs are stored and then displayed. For example:
Shows up in the dashboard as:
{ "Key 0": { "002mm": 31.4 } }because the flatten step produces
"Key 0.002mm": 31.4and the unflatten step naively splits on every..Fixes #1510
Changes
packages/core/src/v3/utils/flattenAttributes.tskey.replace(/\./g, "\\."). Array indices use bracket notation and don't need escaping.splitOnUnescapedDots()helper that tokenizes a flattened key on unescaped dots and unescapes\.back to.in each segment.unflattenAttributesto usesplitOnUnescapedDots(key)instead ofkey.split(".").packages/core/test/flattenAttributes.test.ts{ "Key 0.002mm": 31.4 }round-trips correctly through flatten → unflatten.{ outer: { "a.b": { inner: 1 } } }.How did you test this code?
Added two test cases in the existing
flattenAttributes.test.tsthat reproduce the exact scenario from the issue.