Skip to content

Commit

Permalink
chore: restrict uploadable image types (#7269)
Browse files Browse the repository at this point in the history
* chore: restrict image format

* chore: code cleanup
  • Loading branch information
richardshiue authored Jan 23, 2025
1 parent 862e562 commit a79f825
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ class CopyButton extends StatelessWidget {
size: const Size.square(16),
),
onPressed: () async {
final messageText = textMessage.text.trim();
final document = customMarkdownToDocument(
textMessage.text,
messageText,
tableWidth: 250.0,
);
await getIt<ClipboardService>().setData(
ClipboardServiceData(
plainText: _getTrimmedPlainText(textMessage.text),
plainText: _stripMarkdownIfNecessary(messageText),
inAppJson: jsonEncode(document.toJson()),
),
);
Expand All @@ -186,9 +187,10 @@ class CopyButton extends StatelessWidget {
);
}

String _getTrimmedPlainText(String plainText) {
String _stripMarkdownIfNecessary(String plainText) {
// match and capture inner url as group
final matches = singleLineMarkdownImageRegex.allMatches(plainText);

if (matches.length != 1) {
return plainText;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_p
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart';
import 'package:appflowy/shared/clipboard_state.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/default_extensions.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
Expand Down Expand Up @@ -247,7 +248,8 @@ Future<bool> _isImageUrl(String text) async {
if (response.statusCode == 200) {
final contentType = response.headers['content-type'];
if (contentType != null) {
return contentType.startsWith('image/');
return contentType.startsWith('image/') &&
defaultImageExtensions.any(contentType.contains);
}
}

Expand Down
10 changes: 0 additions & 10 deletions frontend/appflowy_flutter/lib/util/default_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,3 @@ const List<String> defaultImageExtensions = [
'webp',
'bmp',
];

extension ImageStringExtension on String {
bool isImageUrl() {
final imagePattern = RegExp(
r'\.(jpe?g|png|gif|webp|bmp)$',
caseSensitive: false,
);
return imagePattern.hasMatch(this);
}
}

0 comments on commit a79f825

Please sign in to comment.