Fix accessibility anchor issue 77/324877/2
authorBowon Ryu <bowon.ryu@samsung.com>
Wed, 28 May 2025 06:24:21 +0000 (15:24 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Wed, 28 May 2025 09:43:19 +0000 (18:43 +0900)
- 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 <bowon.ryu@samsung.com>
dali-toolkit/internal/text/controller/text-controller-impl.cpp

index 756fda462f57eb1ad1aa3d1079365addbe4b5de1..20aeb95bb09f117590b820bea66429e5d255ca35 100644 (file)
@@ -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<int>(anchor.startIndex));
   actor.SetProperty(Toolkit::TextAnchor::Property::END_CHARACTER_INDEX, static_cast<int>(anchor.endIndex));
   return actor;