appflowy-editor icon indicating copy to clipboard operation
appflowy-editor copied to clipboard

[Bug] markdown to document with image from storage

Open g-apparence opened this issue 2 years ago • 1 comments

Bug Description

Markdown to document doesn't work on image with properties after extension.

When you have an image from for example firebase storage it has an url like https://firebase.com/filename.jpg?alt=media&token=823990382903

How to Reproduce

Create a markdown with an image hosted on a S3 with the token in url

Expected Behavior

We should have an image

Operating System

all

AppFlowy Editor Version(s)

2.3.2

Screenshots

No response

Additional Context

This is where the code is wrong

file: document_markdown_decoder.dart line : 208

if (imageRegex.hasMatch(line.trim())) {
      final filePath = extractImagePath(line.trim());
      // checking if filepath is present or if the filepath is an image or not
      if (filePath == null ||
          !['.png', '.jpg', 'jpeg'].contains(p.extension(filePath))) {
        return paragraphNode(text: line.trim());
      }
      return imageNode(url: filePath);
    }

Here is a solution to fix this

final filePath = extractImagePath(line.trim());
if (filePath == null) {
  return paragraphNode(text: line.trim());
}
final uri = Uri.parse(filePath);
final fileExtension = p.extension(uri.path);

// checking if filepath is present or if the filepath is an image or not
if (!['.png', '.jpg', 'jpeg'].contains(fileExtension)) {
  return paragraphNode(text: line.trim());
}

g-apparence avatar Feb 20 '24 14:02 g-apparence

@g-apparence Thanks for reporting. Can you submit a PR to fix it?

LucasXu0 avatar Feb 25 '24 12:02 LucasXu0