From da26f0848ca893c0bd486b7b9341e2181207b836 Mon Sep 17 00:00:00 2001 From: Bowon Ryu Date: Wed, 28 May 2025 15:24:21 +0900 Subject: [PATCH] Fix accessibility anchor issue - UTF-8 encoding is required. - Previously, assigning UTF-32 characters to std::string worked by coincidence. - In corner cases, the href of an anchor can be nullptr. - Assigning nullptr to std::string can cause a crash. Change-Id: I247b118408daaeb4f0560e167daa33e06e01614b Signed-off-by: Bowon Ryu --- .../text/controller/text-controller-impl.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dali-toolkit/internal/text/controller/text-controller-impl.cpp b/dali-toolkit/internal/text/controller/text-controller-impl.cpp index 756fda462f..20aeb95bb0 100644 --- a/dali-toolkit/internal/text/controller/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/controller/text-controller-impl.cpp @@ -1753,9 +1753,18 @@ Toolkit::TextAnchor Controller::Impl::CreateAnchorActor(Anchor anchor) actor.SetProperty(Actor::Property::POSITION, anchorPosition); const Vector2 anchorSize = GetAnchorSize(anchor); actor.SetProperty(Actor::Property::SIZE, anchorSize); - std::string anchorText(mModel->mLogicalModel->mText.Begin() + anchor.startIndex, mModel->mLogicalModel->mText.Begin() + anchor.endIndex); + + std::string anchorText; + std::string anchorHref = anchor.href ? anchor.href : ""; + Length numberOfAnchorCharacters = anchor.endIndex - anchor.startIndex; + if(numberOfAnchorCharacters > 0u && mModel->mLogicalModel->mText.Size() >= numberOfAnchorCharacters) + { + Utf32ToUtf8(mModel->mLogicalModel->mText.Begin() + anchor.startIndex, numberOfAnchorCharacters, anchorText); + } + DALI_LOG_INFO(gLogFilter, Debug::General, "CreateAnchorActor NAME:%s, URI:%s\n", anchorText.c_str(), anchorHref.c_str()); + actor.SetProperty(Actor::Property::NAME, anchorText); - actor.SetProperty(Toolkit::TextAnchor::Property::URI, std::string(anchor.href)); + actor.SetProperty(Toolkit::TextAnchor::Property::URI, anchorHref); actor.SetProperty(Toolkit::TextAnchor::Property::START_CHARACTER_INDEX, static_cast(anchor.startIndex)); actor.SetProperty(Toolkit::TextAnchor::Property::END_CHARACTER_INDEX, static_cast(anchor.endIndex)); return actor; -- 2.34.1