From 71b6a08b837aea5c122fd76345dcca977d575370 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 21 Nov 2019 13:45:23 -0500 Subject: [PATCH] 1595548: Fix truncation of string list items (#517) * 1595548: Fix truncation of string list items * Add CHANGELOG entry --- CHANGELOG.md | 4 ++++ glean-core/src/metrics/string_list.rs | 2 +- glean-core/tests/string_list.rs | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1151503a..c0e2cda0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ * The experiments API is no longer ignored before the Glean SDK initialized. Calls are recorded and played back once the Glean SDK is initialized. + * String list items were being truncated to 20, rather than 50, bytes when using + `.set()` (rather than `.add()`). This has been corrected, but it may result + in changes in the sent data if using string list items longer than 20 bytes. + # v21.1.1 (2019-11-20) [Full changelog](https://github.com/mozilla/glean/compare/v21.1.0...v21.1.1) diff --git a/glean-core/src/metrics/string_list.rs b/glean-core/src/metrics/string_list.rs index 5acc106db..f5ad2fcbf 100644 --- a/glean-core/src/metrics/string_list.rs +++ b/glean-core/src/metrics/string_list.rs @@ -113,7 +113,7 @@ impl StringListMetric { let value = value .into_iter() .map(|elem| { - truncate_string_at_boundary_with_error(glean, &self.meta, elem, MAX_LIST_LENGTH) + truncate_string_at_boundary_with_error(glean, &self.meta, elem, MAX_STRING_LENGTH) }) .collect(); diff --git a/glean-core/tests/string_list.rs b/glean-core/tests/string_list.rs index 41adee84f..5da8e0b99 100644 --- a/glean-core/tests/string_list.rs +++ b/glean-core/tests/string_list.rs @@ -133,6 +133,20 @@ fn long_string_values_are_truncated() { Ok(1), test_get_num_recorded_errors(&glean, metric.meta(), ErrorType::InvalidValue, None) ); + + metric.set(&glean, vec![test_string.clone()]); + + // Ensure the string was truncated to the proper length. + assert_eq!( + vec![test_string[..50].to_string()], + metric.test_get_value(&glean, "store1").unwrap() + ); + + // Ensure the error has been recorded. + assert_eq!( + Ok(2), + test_get_num_recorded_errors(&glean, metric.meta(), ErrorType::InvalidValue, None) + ); } #[test]