platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.19k stars 80 forks source link

Bug: random deletion of characters/words/line breaks throughout the note #1111

Closed hmu-duc-anh closed 2 months ago

hmu-duc-anh commented 3 months ago

Describe the Bug

Never had this problem before, but in the past week it's been frequent since I updated to the latest version (1.24.0) via Obsidian's community plugins update function. I did some testing and found out that there was something wrong in the communication of linting YAML and linting content. I narrowed down to 2 features: "Remove trailing space" and "Add created/modified date". In a note, especially with lots of square brackets like images, the linting will remove random characters/words, sometimes even line breaks, throughout the entire note's content. I got around by turning off 1 of those 2 features, linted, then turned the other on and linted once more. I decided to download an older version (1.20.1) and those 2 features along with many others worked well together.

Device

pjkaufman commented 3 months ago

Hey @hmu-duc-anh , could you provide your data.json and a file to reproduce the issue with?

hmu-duc-anh commented 3 months ago

Hey @hmu-duc-anh , could you provide your data.json and a file to reproduce the issue with?

Hi. The data.json has been updated with my new settings for the older Linter version, and I have manually fixed all my files. I don't want to forcefully recreate this error since I don't want to risk damaging my data. I can give a file in similar style with placeholder contents, hopefully it can be used to reproduce this bug.

test_linter_bug.md

This mock file represents a type of note that I use to generate Anki cards from Obsidian. It has:

In the latest version of Linter (1.24.0 as of now), whenever I linted to add created/modified dates and remove trailing space, these following phenomenons usually occured:

pjkaufman commented 3 months ago

This sounds a lot like an issue that was fixed in beta version 1.25.0-rc-1. It is a BRAT release that I am planning on releasing to everyone soon.

Is the YAML getting broken?

hmu-duc-anh commented 3 months ago

This sounds a lot like an issue that was fixed in beta version 1.25.0-rc-1. It is a BRAT release that I am planning on releasing to everyone soon.

Is the YAML getting broken?

Nope, YAML still intact

pjkaufman commented 3 months ago

Gotcha. I will have to take a look and see if I can reproduce in the beta version of the Linter.

pjkaufman commented 3 months ago

So far with the information provided, I am not able to reproduce this issue. If you are able to upload your data.json even with the new changes, I may be able to reproduce. Without it, I am not able to reproduce. This could mean that the issue is fixed in the beta release or it could just mean that the settings do not overlap enough with the ones you have for the issue to occur.

hmu-duc-anh commented 3 months ago

So far with the information provided, I am not able to reproduce this issue. If you are able to upload your data.json even with the new changes, I may be able to reproduce. Without it, I am not able to reproduce. This could mean that the issue is fixed in the beta release or it could just mean that the settings do not overlap enough with the ones you have for the issue to occur.

Hi @pjkaufman , I've reupdated and reproduced the bugs. I couldn't also reproduce the bug with previous test file, I think it has something to do with non-English characters, or Unicode characters. Here's my new test files with Vietnamese, Greek and English letters:

Test file before linting: test_linter_bug_before.md

Test file after linting: test_linter_bug_after.md

Linter's data file: data.json

My intended Linter's features are:

You'll see in the linted test file that the random deletion is everywhere except for YAML. Anki card fields are messed up, characters randomly removed and bold, even the embedded images are broken due to random deletion. You can try pasting your own images and see. And I made the test file short because if it was long, the linting process would take up to like 5-10 seconds, it would make a total chaos of the note and wouldn't even delete all trailing spaces, so I could literally lint once more to further malform my file lol.

sevmonster commented 2 months ago

I also encounter this. The only thing I did after installing Linter is adjust settings.

data.json

Diff:

<   - context/date/published/2023-02-13
<   - purpose/review
---
> - purpose/review
> - context/date/published/2023-02-13
13d12
<
57c56
< The FlexFold dividers ae attached with Velc— Ahem, *non-trademarked, unencumbered hook & loop material* to the front and back of the inside of the bag. The hook side is on the divider, and the loop side is very soft, so you don’t have to worry about scratching anything.
---
> The FlexFold dividers are attached with Velc— Ahem, *non-trademarked, unencumbered hook & loop material* to the front and back of the inside of the bag. The hook side is on the divider, and the loop side is very soft, so you don’t have to worry about scratching anything.
89c88
< ![[EverSday Backpack v2 laptop sleeve.jpg|You can kinda get in there if you bend the arch down, but you can clearly feel the bag was not meant to be opened like this, and prolonged bending may ruin the shaping]]
---
> ![[Everyday Backpack v2 laptop sleeve.jpg|You can kinda get in there if you bend the arch down, but you can clearly feel the bag was not meant to be opened like this, and prolonged bending may ruin the shaping]]

In this example, the removal of the space around the em dash is offset, and the replacement of the lowercase S to uppercase in an H1 immediately below the image link (not sure why it wanted to do that) was also offset.

pjkaufman commented 2 months ago

This sounds a lot like the issue fixed in the beta version, but I will double check that this is not different and does happen in the beta with the provided test files.

pjkaufman commented 2 months ago

@hmu-duc-anh , this does look to be fixed in the version that is in beta. I am not 100% sure that it is fixed, but running the Linter on the latest with what is on master (slightly ahead of the beta changes) does not reproduce the issue reported here. I will see about creating a release for these changes.

sevmonster commented 2 months ago

On 1.25.0-rc-1, I can reproduce the issue in the exact same way no longer reproduce it. Had to reload the plugin. Thank you.

pjkaufman commented 2 months ago

@hmu-duc-anh , I just released 1.25.0. Please let me know if that does not fix the issue. I plan to close this Wednesday if I have not heard from you by then.

hmu-duc-anh commented 2 months ago

@pjkaufman I confirm that I can't reproduce the bug with v1.25.0 in Obsidian

pjkaufman commented 2 months ago

Nice. I will go ahead and close this then. I am glad this is resolved.

s1rens commented 2 months ago

I am getting this bug with v1.25.0. As @hmu-duc-anh advised, I get it when using 'remove trailing whitespace' feature. Turning it off removes the issue.

data.json

hmu-duc-anh commented 2 months ago

@s1rens did you make sure to reload Obsidian after updating to 1.25.0? And perhaps you should also provide the devs sample files before and after linting

pjkaufman commented 2 months ago

I fixed another scenario that causes this issue as well (see #1125 ). It also created this scenario. It is fixed on master, but has not been released yet.