superfile icon indicating copy to clipboard operation
superfile copied to clipboard

fix: create item check for dot-entries

Open TheLazron opened this issue 7 months ago • 4 comments

Solves #566

Solution

Added util function to check for the cases where name:

  • equals . or ..
  • has suffix /. or /.. can be used for any further invalid names that may need a check.

Implementation allows for names that might end with dot(s)

Summary by CodeRabbit

  • New Features
    • Added filename validation when creating new files or directories. Invalid filenames (such as ".", "..", or names ending with "/." or "/..") are now prevented.
    • Error messages are displayed in the file naming modal when invalid filenames are entered.
    • Error messages clear automatically when cancelling file creation.
  • Bug Fixes
    • Improved feedback and validation to prevent invalid file names from being accepted.

TheLazron avatar May 15 '25 18:05 TheLazron

Walkthrough

A new function checkFileNameValidity was added to validate filenames against specific invalid patterns. This validation is integrated at the start of the createItem method in the typing modal handler, blocking creation of items with invalid filenames. The typing modal now tracks error messages, which are rendered conditionally. Additional tests were added for filename validation and file creation. The typing modal cancels also clear error messages.

Changes

File(s) Change Summary
src/internal/function.go Added checkFileNameValidity function to validate filenames against invalid names and suffixes.
src/internal/handle_modal.go Added filename validation at start of createItem; sets error message and aborts on invalid input; deferred cleanup clears error message.
src/internal/type.go Added errorMesssage string field to typingModal struct to hold validation error messages.
src/internal/model_render.go Modified typing modal render function to conditionally display styled error message below input and tip.
src/internal/key_function.go Cleared errorMesssage field when cancelling typing modal to reset error state.
src/internal/common/style.go Added new exported style variable ModalErrorStyle for styling modal error messages.
src/internal/function_test.go Added TestCheckFileNameValidity to test various valid and invalid filename scenarios for checkFileNameValidity.
src/internal/model_file_operations_test.go Added TestFileCreation to test filename validation during file creation in model, including nested directories.

Poem

A bunny checks your file’s good name,
No dots alone, nor sneaky shame.
If endings “/.” or “/..” appear,
The bunny hops away from here!
With careful code and nimble feet,
Only valid files we greet.
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93a51adb17289938d394d4ec89c5d8942e994955 and cbfbfeee470bec445296ae04a50450ef4e073d4b.

📒 Files selected for processing (1)
  • src/internal/model_render.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/internal/model_render.go
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar May 15 '25 18:05 coderabbitai[bot]

Needs work

Thanks for the feedback :D, will make all these changes

TheLazron avatar May 16 '25 04:05 TheLazron

Hey @lazysegtree, I have made the changes you mentioned

TheLazron avatar May 20 '25 12:05 TheLazron

@TheLazron Thanks for the fixes.

If you need any help in fixing the further code improvements that I have pointed out, I can do the changes. Sorry, but the code quality of this project is not so good. I have to be strict in reviews.

By the way, we have an semi-active discord (see ReadMe for badge for discord), in case you didn't knew. You can use that for more free discussion, or get any help required while contributing.

lazysegtree avatar May 21 '25 04:05 lazysegtree

@TheLazron Thanks for the fixes.

If you need any help in fixing the further code improvements that I have pointed out, I can do the changes. Sorry, but the code quality of this project is not so good. I have to be strict in reviews.

By the way, we have an semi-active discord (see ReadMe for badge for discord), in case you didn't knew. You can use that for more free discussion, or get any help required while contributing.

Thanks a lot for pointing these out! >W< Sorry got occupied with some work, will try to fix these today only

TheLazron avatar Jun 04 '25 07:06 TheLazron

@TheLazron There are merge conflicts in this. Can you resolve them? It would be best to rebase this branch with latest main.

And please remove that file named ... that is visible in PR diff. and that comment related to m.typingModal.errorMesssage = ""

lazysegtree avatar Jun 09 '25 14:06 lazysegtree

@TheLazron There are merge conflicts in this. Can you resolve them? It would be best to rebase this branch with latest main.

And please remove that file named ... that is visible in PR diff. and that comment related to m.typingModal.errorMesssage = ""

Can you please check if the following were resolved? I did perform the rebase

Not sure do I need to make another pr from my working branch?

TheLazron avatar Jun 11 '25 11:06 TheLazron