Skip to content

Commit 68c76ba

Browse files
authored
Improve escaping of newlines in metrics key-value store (#1792)
Since otherwise any field that contains a carriage return character could span multiple lines in the internal metrics data store, which then wouldn't be read back in its entirety by `bin/report`, which would lead to a truncated field in Honeycomb. Such characters are much less likely now after #1789, however, they can still be present in the user-provided input in some cases (that ends up in metrics fields like `failure_detail`), plus from a general correctness point of view, the key-value store's attribute saving functions should be escaping all forms of newline characters. I've also changed the escaping strategy to use literal `\n` and `\r` characters so it's possible to distinguish between multi-line and single line (but space delimited) values more easily in Honeycomb. GUS-W-18471014.
1 parent 819fb61 commit 68c76ba

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
## [Unreleased]
44

5+
- Improved internal buildpack metrics handling of attributes that contain newline characters. ([#1792](https://github.com/heroku/heroku-buildpack-python/pull/1792))
56

67
## [v284] - 2025-05-06
78

8-
- Fix parsing of `runtime.txt` and `.python-version` files that contain CRLF characters. ([#1789](https://github.com/heroku/heroku-buildpack-python/pull/1789))
9+
- Fixed parsing of `runtime.txt` and `.python-version` files that contain CRLF characters. ([#1789](https://github.com/heroku/heroku-buildpack-python/pull/1789))
910

1011
## [v283] - 2025-05-06
1112

lib/kvstore.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ kv_set() {
3232
# metadata store or bloating the payload passed back to Vacuole/submitted to Honeycomb given the
3333
# extra content in those cases is not normally useful.)
3434
local value="${3:0:100}"
35-
# Replace newlines since the data store file format requires that keys don't span multiple lines.
36-
value="${value//$'\n'/ }"
35+
# Replace newlines and carriage returns since the data store file format requires that keys don't
36+
# span multiple lines.
37+
value="${value//$'\n'/\\n}"
38+
value="${value//$'\r'/\\r}"
3739

3840
if [[ -f "${f}" ]]; then
3941
echo "${key}=${value}" >>"${f}"

0 commit comments

Comments
 (0)