Use html parser instead of regex to clean composer input
Before sending input to the LLM, we clean the composer input to remove html tags. We relied on regex that we not complete enough and could be bypassed easily. So let's use the html parser available in Dart instead. I also added some tests.
This commit is contained in:
@@ -816,4 +816,20 @@ void main() {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('StringConvert.convertHtmlContentToTextContent', () {
|
||||
test('should preserve line breaks between paragraphs', () {
|
||||
const htmlContent = '<p>First paragraph</p><p>Second paragraph</p><p>Third paragraph</p>';
|
||||
final result = StringConvert.convertHtmlContentToTextContent(htmlContent);
|
||||
|
||||
expect(result, 'First paragraph\nSecond paragraph\nThird paragraph');
|
||||
});
|
||||
|
||||
test('should preserve line breaks for br', () {
|
||||
const htmlContent = '<p>First paragraph</p><div><br></div><p>Second paragraph</p>';
|
||||
final result = StringConvert.convertHtmlContentToTextContent(htmlContent);
|
||||
|
||||
expect(result, 'First paragraph\n\nSecond paragraph');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user