Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug Long URL breaks link tag

Discussion in 'UGUI & TextMesh Pro' started by xucian, Sep 12, 2023.

  1. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    771
    Hello,

    Seems odd that I might be the first to find about this, but I simply can't have "long" links in TMPro.
    Using v3.0.6

    Text:
    <link="https://res.cloudinary.com/cloudinary-marketing/cloudinary-marketing/images//blog/WebP_2000x1100_v1a/WebP_2000x1100_v1a-jpg?_i=AA">@@@@</link>

    Expected render:
    @@@@

    Actual render:
    <link="https://res.cloudinary.com/cloudinary-marketing/cloudinary-marketing/images//blog/WebP_2000x1100_v1a/WebP_2000x1100_v1a-jpg?_i=AA">@@@@


    Edit:
    - Happens in v3.2.0-pre.4 too
    - Using Unity 2022.1.24f1
     
    Last edited: Sep 14, 2023
  2. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    771
  3. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    771
    Alright, I've found the culprit, links over ~120 chars are not supported out of the box, it's a pretty huge limitation.
    I understand that links can be shorter and you can have a mapping in code, but that's seems unnecessarily complicated.

    I've added this code to my current project to increase it to 1024 chars:
    Code (CSharp):
    1.  
    2.     private const int RICH_TEXT_TAG_LENGTH_OVERRIDE = 1024;
    3. #if UNITY_EDITOR
    4.     [UnityEditor.InitializeOnLoadMethod]
    5. #else
    6.     [RuntimeInitializeOnLoadMethod]
    7. #endif
    8.     static void TryFixTMProTagLength()
    9.     {
    10.         // Fixing TMPro to have a bigger tag length. Currently it's just 128 which is peanuts - links can be very long.
    11.         // More specifically, the link tag breaks if the text inside the tag is longer than 128 chars, eg:
    12.         // For <link="http://..">
    13.         // <whatever_is_here_has_to_be_shorter_than_128_chars>
    14.         var fi = typeof(TMP_Text).GetField("m_htmlTag", BindingFlags.NonPublic | BindingFlags.Static);
    15.         var arr = fi.GetValue(null) as char[];
    16.         if (arr.Length < RICH_TEXT_TAG_LENGTH_OVERRIDE)
    17.         {
    18.             Array.Resize(ref arr, RICH_TEXT_TAG_LENGTH_OVERRIDE);
    19.             fi.SetValue(null, arr);
    20.         }
    21.     }
    Link to the latest revision: github