* Sanitizes serialized log attributes by replacing lone surrogates in both * keys and string values with U+FFFD.
(attributes: Attributes)
| 233 | * keys and string values with U+FFFD. |
| 234 | */ |
| 235 | function sanitizeLogAttributes(attributes: Attributes): Attributes { |
| 236 | const sanitized: Attributes = {}; |
| 237 | for (const [key, attr] of Object.entries(attributes)) { |
| 238 | const sanitizedKey = _removeLoneSurrogates(key); |
| 239 | if (attr.type === 'string') { |
| 240 | sanitized[sanitizedKey] = { ...attr, value: _removeLoneSurrogates(attr.value) }; |
| 241 | } else { |
| 242 | sanitized[sanitizedKey] = attr; |
| 243 | } |
| 244 | } |
| 245 | return sanitized; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Replaces unpaired UTF-16 surrogates with U+FFFD (replacement character). |
no test coverage detected