simc / crimson

Fast, efficient and easy-to-use JSON parser and serializer for Dart.
Apache License 2.0
229 stars 6 forks source link

Illegal characters appear when saving long markdown strings. #20

Open acking-you opened 1 year ago

acking-you commented 1 year ago

I want to save markdown text as json file, I first encode the text by base64 and then convert it to json string by this library. But I found that if the markdown file is a little bit more complex, it produces the effect in the picture below. image Even so, the library can still parse the data correctly, I'm not sure if this is a bug or not.

Here is my class code:

@json
class Content {
  @jsonIgnore
  Id id = Isar.autoIncrement;
  String title = "";
  Category category = Category();
  Book book = Book();
  String? detail;
}

Here is the code I used for serialization:

...
final writer = CrimsonWriter();
final contents = await Content.allContent();
ContentBase64Encode(contents);
writer.writeContentOrNullList(contents);
...

Here is the code I used for deserialization:

...
final crimson = Crimson(await file.readAsBytes());
final contents = crimson.readContentOrNullList();
ContentBase64Decode(contents);
...
simc commented 1 year ago

That's very weird. I use Crimson a lot myself and never seen something like that.

Is it possible to provide a small runnable example?

acking-you commented 1 year ago

That's very weird. I use Crimson a lot myself and never seen something like that.

Is it possible to provide a small runnable example?

I created a repository reproduction and wrote a simple example code. github.com/ACking-you/example_code

descript

When I save more complex markdown text, it will trigger the following bug:

uTools_1679837416719 At this point in time the editor will think it is a binary file, the above image is forced to show the appearance of the text.

environment

Compiled environment for the demo:Windows 11