[4.0] Check the pair of tag. 03/210203/1 submit/tizen_4.0/20191001.070109 submit/tizen_4.0/20191002.042442
authorJoogab Yun <joogab.yun@samsung.com>
Fri, 5 Apr 2019 00:19:26 +0000 (09:19 +0900)
committerJoogab Yun <joogab.yun@samsung.com>
Wed, 17 Jul 2019 01:26:42 +0000 (10:26 +0900)
* A crash occurs if markup is used incorrectly.

ex) these samples will crash.
* label.SetProperty( TextLabel::Property::TEXT, "<color=#ffff0000>10:01:49</color>" );
  - <color value=#fff0000> is correct expression.

* label.SetProperty( TextLabel::Property::TEXT, "10:</b>01:49" );

Change-Id: I380d0209dabbd35756f9a0b3829fc4a7f31da7d9

automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp
dali-toolkit/internal/text/markup-processor.cpp

index 825e7d4..9814e71 100644 (file)
@@ -398,8 +398,18 @@ int UtcDaliToolkitTextLabelSetPropertyP(void)
   label.SetProperty( TextLabel::Property::TEXT, "<color value='white'>Markup</color><color value='cyan'>Text</color>" );
   DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::TEXT ), std::string("MarkupText"), TEST_LOCATION );
 
-  application.SendNotification();
-  application.Render();
+  // Check for incomplete marks.
+  label.SetProperty( TextLabel::Property::TEXT, "<color='white'><i>Markup</i><b>Text</b></color>" );
+  DALI_TEST_EQUALS( label.GetProperty<std::string>( TextLabel::Property::TEXT ), std::string("MarkupText"), TEST_LOCATION );
+  try
+  {
+    application.SendNotification();
+    application.Render();
+  }
+  catch( ... )
+  {
+    tet_result(TET_FAIL);
+  }
 
   // Check autoscroll properties
   const int SCROLL_SPEED = 80;
index 25b4616..8a5c774 100755 (executable)
@@ -477,6 +477,12 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
   StyleStack::RunIndex colorRunIndex = 0u;
   StyleStack::RunIndex fontRunIndex = 0u;
 
+  // check tag reference
+  int colorTagReference = 0u;
+  int fontTagReference = 0u;
+  int iTagReference = 0u;
+  int bTagReference = 0u;
+
   // Give an initial default value to the model's vectors.
   markupProcessData.colorRuns.Reserve( DEFAULT_VECTOR_SIZE );
   markupProcessData.fontRuns.Reserve( DEFAULT_VECTOR_SIZE );
@@ -515,12 +521,19 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
 
           // Point the next color run.
           ++colorRunIndex;
+
+          // Increase reference
+          ++colorTagReference;
         }
         else
         {
-          // Pop the top of the stack and set the number of characters of the run.
-          ColorRun& colorRun = *( markupProcessData.colorRuns.Begin() + styleStack.Pop() );
-          colorRun.characterRun.numberOfCharacters = characterIndex - colorRun.characterRun.characterIndex;
+          if( colorTagReference > 0 )
+          {
+            // Pop the top of the stack and set the number of characters of the run.
+            ColorRun& colorRun = *( markupProcessData.colorRuns.Begin() + styleStack.Pop() );
+            colorRun.characterRun.numberOfCharacters = characterIndex - colorRun.characterRun.characterIndex;
+            --colorTagReference;
+          }
         }
       } // <color></color>
       else if( TokenComparison( XHTML_I_TAG, tag.buffer, tag.length ) )
@@ -544,12 +557,19 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
 
           // Point the next free font run.
           ++fontRunIndex;
+
+          // Increase reference
+          ++iTagReference;
         }
         else
         {
-          // Pop the top of the stack and set the number of characters of the run.
-          FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
-          fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
+          if( iTagReference > 0 )
+          {
+            // Pop the top of the stack and set the number of characters of the run.
+            FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
+            fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
+            --iTagReference;
+          }
         }
       } // <i></i>
       else if( TokenComparison( XHTML_U_TAG, tag.buffer, tag.length ) )
@@ -584,12 +604,19 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
 
           // Point the next free font run.
           ++fontRunIndex;
+
+          // Increase reference
+          ++bTagReference;
         }
         else
         {
-          // Pop the top of the stack and set the number of characters of the run.
-          FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
-          fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
+          if( bTagReference > 0 )
+          {
+            // Pop the top of the stack and set the number of characters of the run.
+            FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
+            fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
+            --bTagReference;
+          }
         }
       } // <b></b>
       else if( TokenComparison( XHTML_FONT_TAG, tag.buffer, tag.length ) )
@@ -613,12 +640,19 @@ void ProcessMarkupString( const std::string& markupString, MarkupProcessData& ma
 
           // Point the next free font run.
           ++fontRunIndex;
+
+          // Increase reference
+          ++fontTagReference;
         }
         else
         {
-          // Pop the top of the stack and set the number of characters of the run.
-          FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
-          fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
+          if( fontTagReference > 0 )
+          {
+            // Pop the top of the stack and set the number of characters of the run.
+            FontDescriptionRun& fontRun = *( markupProcessData.fontRuns.Begin() + styleStack.Pop() );
+            fontRun.characterRun.numberOfCharacters = characterIndex - fontRun.characterRun.characterIndex;
+            --fontTagReference;
+          }
         }
       } // <font></font>
       else if( TokenComparison( XHTML_SHADOW_TAG, tag.buffer, tag.length ) )