Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate name after dispose #1213

Merged
merged 3 commits into from
Nov 10, 2024
Merged

Conversation

ZebraVogel94349
Copy link
Contributor

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.

Copy link

codecov bot commented Apr 7, 2024

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 ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adil192
Copy link
Member

adil192 commented Jul 31, 2024

_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

@ZebraVogel94349
Copy link
Contributor Author

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
Copy link
Contributor Author

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.

@adil192 adil192 changed the title fix: validate name when renaming in editor fix: validate name after dispose Nov 10, 2024
@adil192 adil192 merged commit a1f5491 into saber-notes:main Nov 10, 2024
1 check failed
@ZebraVogel94349 ZebraVogel94349 deleted the bugfix branch November 10, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants