[GH-ISSUE #1] [Bug]: Certain descriptions do not handle newline replacements properly #1

Closed
opened 2026-03-23 20:34:29 +00:00 by mirror · 3 comments
Owner

Originally created by @lamusmaser on GitHub (Apr 18, 2024).
Original GitHub issue: https://github.com/tubearchivist/tubearchivist-jf-plugin/issues/1

Originally assigned to: @DarkFighterLuke on GitHub.

As reported in Discord by user @__hetz, there are certain descriptions that are unable to handle newline replacements properly. This seems to be because the <br> tags that are coming in are not being processed correctly, and so they are being seen as open-ended tags that require a closure tag.

This causes the description and rendering of the page to become very distorted and unable to show the video preview properly.

Originally created by @lamusmaser on GitHub (Apr 18, 2024). Original GitHub issue: https://github.com/tubearchivist/tubearchivist-jf-plugin/issues/1 Originally assigned to: @DarkFighterLuke on GitHub. As reported in Discord by user @__hetz, there are certain descriptions that are unable to handle newline replacements properly. This seems to be because the `<br>` tags that are coming in are not being processed correctly, and so they are being seen as open-ended tags that require a closure tag. This causes the description and rendering of the page to become very distorted and unable to show the video preview properly.
Author
Owner

@lamusmaser commented on GitHub (Apr 18, 2024):

As discussed in Discord, this could be remedied with several types of handling.

  1. Changing the ambiguously open tags that require a tag closure with an open/close tag.
  • i.e. <br> -> <br></br>
  1. Changing the ambiguously open tags that require a tag closure with a self-closure tag.
  • i.e. <br> -> <br />
  1. Confirming that the sum of all character replacements do not push the character count beyond the character limit.

This does seem to only be happening on certain browsers/renderings of Jellyfin, The others are handling the break lines properly. Additionally, these were working within the tubearchivist-jf functionality, which was copied over into this. This means that there was an additional post-processor that was handling the occurrences of break lines as they were being rendered, since they were being imported straight through via the Jellyfin API.

<!-- gh-comment-id:2062944585 --> @lamusmaser commented on GitHub (Apr 18, 2024): As discussed in Discord, this could be remedied with several types of handling. 1. Changing the ambiguously open tags that require a tag closure with an open/close tag. - i.e. `<br>` -> `<br></br>` 2. Changing the ambiguously open tags that require a tag closure with a self-closure tag. - i.e. `<br>` -> `<br />` 3. Confirming that the sum of all character replacements do not push the character count beyond the character limit. This does seem to only be happening on certain browsers/renderings of Jellyfin, The others are handling the break lines properly. Additionally, these were working within the `tubearchivist-jf` functionality, which was copied over into this. This means that there was an additional post-processor that was handling the occurrences of break lines as they were being rendered, since they were being imported straight through via the Jellyfin API.
Author
Owner

@ThisIsHetz commented on GitHub (Apr 18, 2024):

I dug up the password for this old account just to chime in.

This issue impacted the Jellyfin app for Android, the latest Windows desktop client (running on Windows 11), as well as the Jellyfin web interface in both the latest Brave and Firefox web browsers (again on Windows 11). The only exception was with an unofficial build of the Jellyfin app for Samsung televisions running Tizen OS. To spare a tangent, I don't have the details for the Tizen app but I believe it is based off an older Android app build and that it was a fluke that it happened to display correctly.

I'm also uncertain there was any additional post-processing. Rather it has to do with the order of operations when the video description is processed from JSON to HTML for Jellyfin. With the old extension, newlines were replaced with HTML breaks only after the description was truncated:

def clean_overview(overview_raw: str) -> str:
    """parse and clean raw overview text"""
    if len(overview_raw) > 500:
        overview_raw = overview_raw[:500] + " ..."

    desc_clean: str = overview_raw.replace("\n", "<br>")

    return desc_clean

With this plugin the truncation occurs after the newlines are replaced:

        public static string FormatDescription(string description)
       {
           var maxLength = 500;
           if (Plugin.Instance != null)
           {
               maxLength = Plugin.Instance.Configuration.MaxDescriptionLength;
           }

           if (description.Length > maxLength)
           {
               description = description.Replace("\n", "<br>", System.StringComparison.CurrentCulture).Substring(0, maxLength);
           }

           return description;
       }
   }
}

When truncation occurs it sometimes leaves an incomplete HTML break (e.g. <b or <br) at the end of a video description which is what breaks the display of video lists. My temporary fix was to separate the two operations such that they behave as the previous extension did:

        public static string FormatDescription(string description)
       {
           var maxLength = 500;
           if (Plugin.Instance != null)
           {
               maxLength = Plugin.Instance.Configuration.MaxDescriptionLength;
           }

           if (description.Length > maxLength)
           {
               description = description.Substring(0, maxLength);
               description = description.Replace("\n", "<br>", System.StringComparison.CurrentCulture);
           }

           return description;
       }
   }
}

As an aside, it may be worth noting that neither the previous extension nor my solution probably abides by the character limit since two characters are going to be gained each time a \n is replaced with a <br>.

<!-- gh-comment-id:2063309683 --> @ThisIsHetz commented on GitHub (Apr 18, 2024): I dug up the password for this old account just to chime in. This issue impacted the Jellyfin app for Android, the latest Windows desktop client (running on Windows 11), as well as the Jellyfin web interface in both the latest Brave and Firefox web browsers (again on Windows 11). The only exception was with an unofficial build of the Jellyfin app for Samsung televisions running Tizen OS. To spare a tangent, I don't have the details for the Tizen app but I believe it is based off an older Android app build and that it was a fluke that it happened to display correctly. I'm also uncertain there was any additional post-processing. Rather it has to do with the order of operations when the video description is processed from JSON to HTML for Jellyfin. With the old extension, newlines were replaced with HTML breaks only after the description was truncated: ```python def clean_overview(overview_raw: str) -> str: """parse and clean raw overview text""" if len(overview_raw) > 500: overview_raw = overview_raw[:500] + " ..." desc_clean: str = overview_raw.replace("\n", "<br>") return desc_clean ``` With this plugin the truncation occurs after the newlines are replaced: ```csharp public static string FormatDescription(string description) { var maxLength = 500; if (Plugin.Instance != null) { maxLength = Plugin.Instance.Configuration.MaxDescriptionLength; } if (description.Length > maxLength) { description = description.Replace("\n", "<br>", System.StringComparison.CurrentCulture).Substring(0, maxLength); } return description; } } } ``` When truncation occurs it sometimes leaves an incomplete HTML break (e.g. `<b` or `<br`) at the end of a video description which is what breaks the display of video lists. My temporary fix was to separate the two operations such that they behave as the previous extension did: ```csharp public static string FormatDescription(string description) { var maxLength = 500; if (Plugin.Instance != null) { maxLength = Plugin.Instance.Configuration.MaxDescriptionLength; } if (description.Length > maxLength) { description = description.Substring(0, maxLength); description = description.Replace("\n", "<br>", System.StringComparison.CurrentCulture); } return description; } } } ``` As an aside, it may be worth noting that neither the previous extension nor my solution probably abides by the character limit since two characters are going to be gained each time a `\n` is replaced with a `<br>`.
Author
Owner

@DarkFighterLuke commented on GitHub (Apr 18, 2024):

Hello guys, the fix proposed by @ThisIsHetz has been merged and a new release is now available.
Thanks for the contribution!

<!-- gh-comment-id:2065156226 --> @DarkFighterLuke commented on GitHub (Apr 18, 2024): Hello guys, the fix proposed by @ThisIsHetz has been merged and a new release is now available. Thanks for the contribution!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tubearchivist/archived-tubearchivist-jf-plugin#1
No description provided.