Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [RUMF-1470] Sanitize - Fix size computation #2116

Merged
merged 2 commits into from
Mar 31, 2023

Conversation

yannickadam
Copy link
Contributor

@yannickadam yannickadam commented Mar 28, 2023

Motivation

sanitize generates telemetry errors (Exception TypeError)

Changes

Proper computation of size for undefined values in objects and arrays

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@yannickadam yannickadam requested a review from a team as a code owner March 28, 2023 14:55
@yannickadam yannickadam changed the title 🐛 Fix size computation 🐛 [RUMF-1470] Sanitize - Fix size computation Mar 28, 2023
accumulatedCharacterCount += JSON.stringify(targetData).length + separatorLength
// When an element of an Array (targetData) is undefined, it is serialized as null:
// JSON.stringify([undefined]) => '[null]' - This accounts for 4 characters
accumulatedCharacterCount += (JSON.stringify(targetData)?.length ?? 4) + separatorLength
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏Maybe it would be easier to understand with an if (targetData !== undefined) condition instead of relying on JSON.stringify(undefined) -> undefined

if (targetData === undefined) {
  // When an element of an Array (targetData) is undefined, it is serialized as null:
  // JSON.stringify([undefined]) => '[null]' - This accounts for 4 characters
  accumulatedCharacterCount += 4
} else {
  accumulatedCharacterCount += JSON.stringify(targetData).length
}
accumulatedCharacterCount += separatorLength

@yannickadam yannickadam merged commit 524a9e8 into main Mar 31, 2023
@yannickadam yannickadam deleted the yannick.adam/RUMF-1470-Sanitize-fix-typeerror branch March 31, 2023 12:30
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.

3 participants