WLED icon indicating copy to clipboard operation
WLED copied to clipboard

Presets file gets corrupted when presets are modified if it contains any spacing

Open B1BU opened this issue 11 months ago • 4 comments

What happened?

If a preset file contains white spaces it loads up properly but gets corrupted when any preset is edited.

Writing the file like {"key":"value"} works.

But writing it like {"key": "value"} doesn't.

It seems WLED tries to overwrite the length of the preset data with spaces and add the new data to the end of the file but it doesn't account for white spaces, so it overwrites the wrong part of the file creating invalid json syntax.

I don't know why you guys chose to overwrite the file like this and I imagine there's probably a reason, but I really wish it would just write the file properly like it does with config files. People have always complained preset files would get corrupted randomly, this seems to be the reason why.

To Reproduce Bug

Add a single space between any key and value of any preset in presets.json and try to modify the same preset.

Expected Behavior

For WLED to overwrite the file properly like it does with cfg.json or maybe convert the json file to the minimized version before overwriting so it doesn't break stuff.

Install Method

Binary from WLED.me

What version of WLED?

WLED 0.14.2-b1

Which microcontroller/board are you seeing the problem on?

ESP32

Relevant log/trace output

No response

Anything else?

People have always complained that presets in WLED can get corrupted randomly. This seems to be why

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

B1BU avatar Feb 27 '24 04:02 B1BU