[Tizen] Fix accessibility anchor issue 46/324946/3
authorBowon Ryu <bowon.ryu@samsung.com>
Wed, 28 May 2025 06:24:21 +0000 (15:24 +0900)
committerYoungsun Suh <youngsun.suh@samsung.com>
Thu, 29 May 2025 07:11:12 +0000 (07:11 +0000)
- 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>
(cherry picked from commit da26f0848ca893c0bd486b7b9341e2181207b836)

dali-toolkit/internal/text/controller/text-controller-impl.cpp

index 146d17d696769c95bb5860b7509518b2fac2781f..5e338bb07571be75d8d392a8e769eecc3b03c5d7 100644 (file)
@@ -1716,9 +1716,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;