TF-3267 Implement HTML attachment preview

This commit is contained in:
DatDang
2024-12-06 10:07:53 +07:00
committed by Dat H. Pham
parent 3ddb81a8c4
commit ac91cae0db
22 changed files with 558 additions and 18 deletions
@@ -143,5 +143,35 @@ void main() {
expect(result, equals('<img src="cid:email123">'));
});
test(
'SHOULD persist nav tag and remove href attribute of A tag '
'WHEN href is invalid',
() {
const inputHtml = '<nav href="javascript:alert(1)"></nav>';
final result = transformer.process(inputHtml, htmlEscape);
expect(result, equals('<nav></nav>'));
});
test(
'SHOULD persist main tag and remove href attribute of A tag '
'WHEN href is invalid',
() {
const inputHtml = '<main href="javascript:alert(1)"></main>';
final result = transformer.process(inputHtml, htmlEscape);
expect(result, equals('<main></main>'));
});
test(
'SHOULD persist footer tag and remove href attribute of A tag '
'WHEN href is invalid',
() {
const inputHtml = '<footer href="javascript:alert(1)"></footer>';
final result = transformer.process(inputHtml, htmlEscape);
expect(result, equals('<footer></footer>'));
});
});
}
+88
View File
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:core/domain/exceptions/string_exception.dart';
import 'package:core/utils/string_convert.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -159,4 +160,91 @@ void main() {
});
});
});
group('string convert test:', () {
const testText = 'Hello';
test(
'should use utf8 decoder '
'when isHtml is true',
() {
// arrange
final bytes = utf8.encode(testText);
// act
final result = StringConvert.decodeFromBytes(bytes, charset: null, isHtml: true);
// assert
expect(result, testText);
});
test(
'should use utf8 decoder '
'when charset contains utf-8',
() {
// arrange
final bytes = utf8.encode(testText);
// act
final result = StringConvert.decodeFromBytes(bytes, charset: 'utf-8');
// assert
expect(result, testText);
});
test(
'should use latin1 decoder '
'when charset contains latin-1',
() {
// arrange
final bytes = latin1.encode(testText);
// act
final result = StringConvert.decodeFromBytes(bytes, charset: 'latin-1');
// assert
expect(result, testText);
});
test(
'should use ascii decoder '
'when charset contains ascii',
() {
// arrange
final bytes = ascii.encode(testText);
// act
final result = StringConvert.decodeFromBytes(bytes, charset: 'ascii');
// assert
expect(result, testText);
});
test(
'should throw NullCharsetException '
'when charset is null',
() {
// arrange
final bytes = utf8.encode(testText);
// assert
expect(
() => StringConvert.decodeFromBytes(bytes, charset: null),
throwsA(isA<NullCharsetException>()),
);
});
test(
'should throw UnsupportedCharsetException '
'when charset is unsupported',
() {
// arrange
final bytes = utf8.encode(testText);
// assert
expect(
() => StringConvert.decodeFromBytes(bytes, charset: 'unsupported'),
throwsA(isA<UnsupportedCharsetException>()),
);
});
});
}