Properly escape HTML in every Scribe actions

In recent commits I separated how we could add text in the editor. So
we need to escape HTML in both method that add text:
insertTextInEditor and setTextInEditor.

I had to extract the HTML escape part of
convertTextContentToHtmlContent because when using setTextInEditor we
do not need to convert \n to <br>.
This commit is contained in:
Théo Poizat
2026-01-27 11:21:10 +01:00
committed by Dat H. Pham
parent cf8ed16ed0
commit 40030fe88e
2 changed files with 14 additions and 13 deletions
@@ -36,7 +36,8 @@ extension HandleAiScribeInComposerExtension on ComposerController {
Future<void> insertTextInEditor(String text) async {
try {
final htmlContent = StringConvert.convertTextContentToHtmlContent(text);
final escapedText = StringConvert.escapeTextContent(text);
final htmlContent = StringConvert.convertTextContentToHtmlContent(escapedText);
if (PlatformInfo.isWeb) {
await richTextWebController?.editorController.evaluateJavascriptWeb(
@@ -55,13 +56,15 @@ extension HandleAiScribeInComposerExtension on ComposerController {
Future<void> setTextInEditor(String text) async {
try {
final escapedText = StringConvert.escapeTextContent(text);
if (PlatformInfo.isWeb) {
richTextWebController?.editorController.setText(text);
richTextWebController?.editorController.setText(escapedText);
} else {
await richTextMobileTabletController?.htmlEditorApi?.setText(text);
await richTextMobileTabletController?.htmlEditorApi?.setText(escapedText);
}
} catch (e) {
logWarning('$runtimeType::insertTextInEditor:Exception = $e');
logWarning('$runtimeType::setTextInEditor:Exception = $e');
}
}