From 68d4978b7d7ee4aa6200ce6d096c50081242c45a Mon Sep 17 00:00:00 2001 From: Maxim Beder Date: Mon, 3 Apr 2023 23:49:33 +0200 Subject: [PATCH] Add test for summary truncating long anotations When calling summary command with :annotations hint, if the annotation is longer than a certain length, it's going to be truncated. The issue is that the length and truncation are done on a raw string without considering UTF8 multibyte characters, so there are edge cases when an annotation is truncated in the middle of a character creating an invalid UTF8 string. Added a test case for this scenario. Signed-off-by: Maxim Beder --- test/summary.t | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/summary.t b/test/summary.t index 0b88da4c..e6dd683f 100755 --- a/test/summary.t +++ b/test/summary.t @@ -352,6 +352,16 @@ W\d{1,2} \d{4}-\d{2}-\d{2} .{3} ?0:00:00 0:00:00 0:00:00 0:00:00 [ ]+0:00:00 """) + def test_multibyte_char_annotation_truncated(self): + """Summary correctly truncates long annotation containing multibyte characters""" + # Using a blue heart emoji as an example of a multibyte (4 bytes in + # this case) character. + long_enough_annotation = "a" + "\N{blue heart}" * 20 + self.t("track FOO sod - sod") + self.t("anno @1 " + long_enough_annotation) + code, out, err = self.t("summary :anno") + self.assertIn("a" + "\N{blue heart}" * 11 + "...", out) + if __name__ == "__main__": from simpletap import TAPTestRunner