Fix HTML tags rendered as plain text in received notifications - #43
Open
shalin-dev wants to merge 1 commit into
Open
Fix HTML tags rendered as plain text in received notifications#43shalin-dev wants to merge 1 commit into
shalin-dev wants to merge 1 commit into
Conversation
When receiving notifications from the desktop, HTML tags (<b>, <i>, <br>, etc.) were displayed as raw text in the Android notification shade instead of being rendered or stripped. Parse notification text through Html.fromHtml() before passing it to NotificationCompat.Builder. This strips HTML tags and preserves intended formatting (bold, italic) as Spanned text that Android notifications can render natively. Fixes ZorinOS#17 Co-authored-by: shalin-dev <shalin@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #17
Problem
When receiving notifications from the desktop, HTML tags (
<b>,<i>,<br>, etc.) were displayed as raw text in the Android notification shade instead of being rendered or stripped.This happens because
ReceiveNotificationsPlugin.onPacketReceived()passes the notification ticker text directly toNotificationCompat.Builderwithout parsing HTML.Fix
Parse notification text through
Html.fromHtml()before passing it to the notification builder. This strips HTML tags and preserves intended formatting (bold, italic) asSpannedtext that Android notifications can render natively.Changes
import android.text.HtmltoReceiveNotificationsPlugin.javafromHtml()helper method with API level compatibility (usesFROM_HTML_MODE_COMPACTon API 24+, falls back to deprecated overload on older versions)setContentText(),setTicker(), andBigTextStyle.bigText()<nor&charactersTesting
fromHtml()logic with 14 unit tests covering: plain text identity, bold/italic/br/p tag stripping, HTML entity decoding, malformed HTML, and empty stringspackage-private staticto allow direct unit testing without reflectionScreenshots (expected behavior)
Before: Notification shows
<b>Important</b> messageas raw textAfter: Notification shows Important message with bold styling applied