saber icon indicating copy to clipboard operation
saber copied to clipboard

fix: validate name when renaming in editor

Open ZebraVogel94349 opened this issue 1 year ago • 4 comments

I've noticed that validation of the new name when renaming a note in the editor doesn't work, so you can rename a note to an empty name or a name containing slashes from the editor. The problem was that _filenameFormKey.currentState?.validate() ?? true is always a string or true, but it should be false if the function returns null. I've also fixed a bug which made it impossible to save a note after renaming it in the editor but before the new name has been applied.

ZebraVogel94349 avatar Apr 07 '24 17:04 ZebraVogel94349

Codecov Report

Attention: Patch coverage is 50.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 36.97%. Comparing base (f3afcea) to head (a2a29c5).

Files Patch % Lines
lib/pages/editor/editor.dart 50.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1213      +/-   ##
==========================================
+ Coverage   36.93%   36.97%   +0.04%     
==========================================
  Files         111      111              
  Lines        8715     8716       +1     
==========================================
+ Hits         3219     3223       +4     
+ Misses       5496     5493       -3     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Apr 07 '24 17:04 codecov[bot]

_filenameFormKey.currentState?.validate() ?? true is always a string or true

The [FormState.validate] function returns true if there are no errors, otherwise false. Dart wouldn't accept an "if (string)" anyway.

I've also fixed a bug which made it impossible to save a note after renaming it in the editor but before the new name has been applied.

I'll need to look at this further but I don't have time rn

adil192 avatar Jul 31 '24 22:07 adil192

The [FormState.validate] function returns true if there are no errors, otherwise false. Dart wouldn't accept an "if (string)" anyway.

You're right, that doesn't solve the issue. I misunderstood how the validate() function works.

ZebraVogel94349 avatar Aug 01 '24 09:08 ZebraVogel94349

I've fixed it now. When you exit the editor after renaming the file, but before it has been saved, _filenameFormKey.currentState is null, so _filenameFormKey.currentState?.validate() ?? true is true and the file will be renamed, even though the validation didn't happen. By calling _validateFilenameTextField(newName) directly, the name is always validated.

ZebraVogel94349 avatar Aug 01 '24 15:08 ZebraVogel94349