Merge pull request #1220 from AppFlowy-IO/fix/html-comment-leak-in-delta

fix: don't leak HTML comment content into pasted paragraph text
This commit is contained in:
Nathan.fooo 2026-07-07 14:09:39 +08:00 • committed by GitHub
commit e95e16a2ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -470,9 +470,11 @@ class DocumentHTMLDecoder extends Converter<String, Document> {
); );
} }
} }
} else { } else if (child is dom.Text) {
delta.insert(child.text?.replaceAll(RegExp(r'\n+$'), '') ?? ''); delta.insert(child.text.replaceAll(RegExp(r'\n+$'), ''));
} }
// other node types (e.g. dom.Comment) carry no visible content and
// are intentionally skipped, mirroring _parseElement's handling.
} }
return (delta, nodes); return (delta, nodes);

View file

@ -41,5 +41,21 @@ void main() {
isTrue, isTrue,
); );
}); });
test('paste text with an inline HTML comment does not leak comment text',
() {
// Some sites (e.g. Google Search AI Overview) inject an HTML comment
// into copied content as an internal marker. It must not surface as
// visible text, regardless of what the comment contains.
const html = '''
<p>First answer<!--TgQPHd||[]--></p>
<p>Second answer<!-- some other internal marker --></p>
''';
final document = htmlToDocument(html);
final children = document.root.children;
expect(children[0].delta!.toPlainText(), 'First answer');
expect(children[1].delta!.toPlainText(), 'Second answer');
});
}); });
} }