Skip to content

Commit 70abbf2

Browse files
committed
fix #479: Add bubble text length limit
1 parent 35ea917 commit 70abbf2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/scratch/target.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ const std::string &Target::bubbleText() const
466466
*/
467467
void Target::setBubbleText(const std::string &text)
468468
{
469-
impl->bubbleText = text;
469+
size_t limit = 330;
470+
impl->bubbleText = text.substr(0, limit);
470471
}
471472

472473
/*! Returns the engine. */

test/scratch_classes/target_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,25 @@ TEST(TargetTest, BubbleText)
603603

604604
target.setBubbleText("world");
605605
ASSERT_EQ(target.bubbleText(), "world");
606+
607+
// longstr.length = 384, should be limited to 330 in bubble text
608+
std::string longstr =
609+
"EY8OUNzAqwgh7NRGk5TzCP3dkAhJy9TX"
610+
"Y9mqKElPjdQpKddYqjyCwUk2hx6YgVZV"
611+
"6BOdmZGxDMs8Hjv8W9G6j4gTxAWdOkzs"
612+
"8Ih80xzEDbvLilWsDwoB6FxH2kVVI4xs"
613+
"IXOETNQ6QMsCKLWc5XjHk2BS9nYvDGpJ"
614+
"uEmp9zIzFGT1kRSrOlU3ZwnN1YtvqFx"
615+
"3hkWVNtJ71dQ0PJHhOVQPUy19V01SPu3"
616+
"KIIS2wdSUVAc4RYMzepSveghzWbdcizy"
617+
"Tm1KKAj4svu9YoL8b9vsolG8gKunvKO7"
618+
"MurRKSeUbECELnJEKV6683xCq7RvmjAu"
619+
"2djZ54apiQc1lTixWns5GoG0SVNuFzHl"
620+
"q97qUiqiMecjVFM51YVif7c1Stip52Hl";
621+
622+
target.setBubbleText(longstr);
623+
ASSERT_EQ(target.bubbleText().length(), 330);
624+
ASSERT_EQ(target.bubbleText(), longstr.substr(0, 330));
606625
}
607626

608627
TEST(TargetTest, Engine)

0 commit comments

Comments
 (0)