Repository navigation
fix: HTML parsing/normalization flow adjustments #815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hejsztynx
wants to merge
7
commits into
main
Choose a base branch
from
@ksienkiewicz/fix-ios-initial-html-processing-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c7c4279
fix: drop the length check
hejsztynx 7955e4c
fix: safe body tag search
hejsztynx eb4247a
fix: wrap parsing call with a try catch block
hejsztynx 8e68251
fix(ios): adjusted the normalization flow
hejsztynx b610476
fix(android): adjusted the normalization flow
hejsztynx ba6778c
fix(web): adjusted the normalization flow
hejsztynx 97a8e3c
chore: update baselines
hejsztynx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+12 Bytes
(100%)
.maestro/enrichedInput/screenshots/android/checkbox_toggle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+892 Bytes
(100%)
.../enrichedInput/screenshots/android/mention_popup_closing_on_cursor_travel_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+854 Bytes
(100%)
.../enrichedInput/screenshots/android/mention_popup_closing_on_cursor_travel_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+822 Bytes
(100%)
.../enrichedInput/screenshots/android/mention_popup_closing_on_cursor_travel_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+14 Bytes
(100%)
.maestro/enrichedInput/screenshots/android/paragraph_styles_lists.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+72 Bytes
(100%)
.maestro/enrichedInput/screenshots/android/paragraph_styles_no_crash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-3 Bytes
(100%)
.maestro/enrichedText/screenshots/android/custom_styles_display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions
28
android/src/main/java/com/swmansion/enriched/common/parser/HtmlWrapperExtractor.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.swmansion.enriched.common.parser | ||
|
|
||
| object HtmlWrapperExtractor { | ||
| private const val HTML_OPEN = "<html>" | ||
| private const val HTML_CLOSE = "</html>" | ||
| private const val BODY_OPEN = "<body>" | ||
| private const val BODY_CLOSE = "</body>" | ||
|
|
||
| /** | ||
| * Strips the <html> tags and, if there is a <body> pair inside, keeps only its content | ||
| * (anything outside of it is dropped). | ||
| */ | ||
| fun extract(html: String): String { | ||
| val trimmed = html.trim() | ||
| if (!trimmed.startsWith(HTML_OPEN) || !trimmed.endsWith(HTML_CLOSE)) return html | ||
|
|
||
| val inner = trimmed.substring(HTML_OPEN.length, trimmed.length - HTML_CLOSE.length) | ||
| val bodyStart = inner.indexOf(BODY_OPEN) | ||
| if (bodyStart == -1) return inner | ||
|
|
||
| val contentStart = bodyStart + BODY_OPEN.length | ||
| // only look for the closing tag after the opening one | ||
| val bodyEnd = inner.indexOf(BODY_CLOSE, contentStart) | ||
| if (bodyEnd == -1) return inner | ||
|
|
||
| return inner.substring(contentStart, bodyEnd) | ||
| } | ||
| } | ||
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| const HTML_OPEN = '<html>'; | ||
| const HTML_CLOSE = '</html>'; | ||
| const BODY_OPEN = '<body>'; | ||
| const BODY_CLOSE = '</body>'; | ||
|
|
||
| /** | ||
| * Strips the <html> tags and, if there is a <body> pair inside, keeps only its content | ||
| * (anything outside of it is dropped). | ||
| * | ||
| * Must run before sanitization, as DOMPurify drops these tags and would leave | ||
| * content from outside of <body> in the result. | ||
| */ | ||
| export function extractHtmlContent(html: string): string { | ||
| const trimmed = html.trim(); | ||
| if (!trimmed.startsWith(HTML_OPEN) || !trimmed.endsWith(HTML_CLOSE)) { | ||
| return html; | ||
| } | ||
|
|
||
| const inner = trimmed.slice(HTML_OPEN.length, -HTML_CLOSE.length); | ||
| const bodyStart = inner.indexOf(BODY_OPEN); | ||
|
hejsztynx marked this conversation as resolved.
|
||
| if (bodyStart === -1) return inner; | ||
|
|
||
| const contentStart = bodyStart + BODY_OPEN.length; | ||
| // only look for the closing tag after the opening one | ||
| const bodyEnd = inner.indexOf(BODY_CLOSE, contentStart); | ||
| if (bodyEnd === -1) return inner; | ||
|
|
||
| return inner.slice(contentStart, bodyEnd); | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.