-
-
Notifications
You must be signed in to change notification settings - Fork 414
fix: create item check for dot-entries #817
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: create item check for dot-entries #817
Conversation
WalkthroughA new function Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (2)
src/internal/function.go(1 hunks)src/internal/handle_modal.go(1 hunks)
🧰 Additional context used
🪛 golangci-lint (1.64.8)
src/internal/function.go
217-217: dupCase: 'case name == "."' is duplicated
(gocritic)
🔇 Additional comments (1)
src/internal/handle_modal.go (1)
29-31: LGTM: Properly validates filenames before creationThe implementation correctly checks if the filename is valid before attempting to create it, and returns early if validation fails. The placement right after the defer block ensures proper cleanup regardless of validation results.
lazysegtree
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs work
Thanks for the feedback :D, will make all these changes |
|
Hey @lazysegtree, I have made the changes you mentioned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (6)
src/internal/function.go (1)
215-224: The filename validation function looks solid, but has some performance optimizations.The implementation correctly validates filenames against special directory entries (
.and..) as specified in the PR objectives, with proper error handling and cross-platform support using the OS-specific path separator.Consider using
errors.Newinstead offmt.Errorfwhen no formatting is needed:func checkFileNameValidity(name string) error { switch { case name == ".", name == "..": - return fmt.Errorf("file name cannot be '.' or '..'") + return errors.New("file name cannot be '.' or '..'") case strings.HasSuffix(name, fmt.Sprintf("%c.", filepath.Separator)), strings.HasSuffix(name, fmt.Sprintf("%c..", filepath.Separator)): - return fmt.Errorf("file name cannot end with '/.' or '/..'") + return errors.New("file name cannot end with '/.' or '/..'") default: return nil } }This would require adding
errorsto the import list.🧰 Tools
🪛 golangci-lint (1.64.8)
218-218: fmt.Errorf can be replaced with errors.New
(perfsprint)
220-220: fmt.Errorf can be replaced with errors.New
(perfsprint)
src/internal/model_file_operations_test.go (1)
82-124: The test cases for file naming validation are comprehensive.The test covers all the required validation cases for filenames, including special directory entries (
.and..), paths ending with/.or/..`, and valid filenames. The test setup and cleanup are properly handled.There's a minor typo in the test case description:
- {"invalid trailig slash-dot-dot", fmt.Sprintf("test%c..", filepath.Separator), true}, + {"invalid trailing slash-dot-dot", fmt.Sprintf("test%c..", filepath.Separator), true},src/internal/function_test.go (4)
10-10: Remove unnecessary newline.There's an extra blank line after the function declaration that should be removed.
-func TestCheckFileNameValidity(t *testing.T) { - +func TestCheckFileNameValidity(t *testing.T) {🧰 Tools
🪛 golangci-lint (1.64.8)
10-10: unnecessary leading newline
(whitespace)
26-26: Fix typo in error message.The error message contains a typo: "cnnot" should be "cannot".
- errMsg: "file name cnnot be '.' or '..'", + errMsg: "file name cannot be '.' or '..'",
31-31: Consider making error messages platform-agnostic.The error messages refer to '/' which might not match the actual separator on Windows systems. Consider using a platform-agnostic message or using the filepath.Separator in the error message construction.
- errMsg: "file name cannot end with '/.' or '/..'", + errMsg: fmt.Sprintf("file name cannot end with '%c.' or '%c..'", filepath.Separator, filepath.Separator),Or ensure the actual implementation of
checkFileNameValidityuses a platform-agnostic approach for error messages.Also applies to: 36-36
73-73: Remove unnecessary trailing newline.There's an extra blank line at the end of the function that should be removed.
-} - +}🧰 Tools
🪛 golangci-lint (1.64.8)
73-73: unnecessary trailing newline
(whitespace)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (7)
src/internal/function.go(1 hunks)src/internal/function_test.go(1 hunks)src/internal/handle_modal.go(1 hunks)src/internal/key_function.go(1 hunks)src/internal/model_file_operations_test.go(3 hunks)src/internal/model_render.go(1 hunks)src/internal/type.go(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/internal/type.go
🚧 Files skipped from review as they are similar to previous changes (1)
- src/internal/handle_modal.go
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/internal/model_file_operations_test.go (3)
src/internal/test_utils.go (1)
TeaUpdateWithErrCheck(53-57)src/internal/utils/tea_utils.go (1)
TeaRuneKeyMsg(5-10)src/internal/common/default_config.go (1)
Hotkeys(12-12)
src/internal/model_render.go (2)
src/internal/common/style_function.go (1)
ModalBorderStyle(120-122)src/internal/common/predefined_variable.go (2)
ModalHeight(21-21)ModalWidth(20-20)
🪛 golangci-lint (1.64.8)
src/internal/function_test.go
10-10: unnecessary leading newline
(whitespace)
73-73: unnecessary trailing newline
(whitespace)
src/internal/function.go
218-218: fmt.Errorf can be replaced with errors.New
(perfsprint)
220-220: fmt.Errorf can be replaced with errors.New
(perfsprint)
🔇 Additional comments (3)
src/internal/key_function.go (1)
208-209: LGTM: Error message clearing on cancel.Clearing the error message when the typing modal is canceled ensures that previous error states don't persist when reopening the modal, providing a clean user experience.
src/internal/model_render.go (1)
410-417: The error message rendering implementation is effective.The code adds appropriate styling to error messages with red text and red border for clear visual feedback when filename validation fails. This enhances user experience by providing immediate, visible feedback about invalid inputs.
src/internal/function_test.go (1)
10-73: The overall test looks good but could use additional validation.The test cases cover various scenarios for the
checkFileNameValidityfunction, which is excellent. However, consider adding validation for the error message in cases where no error is expected to ensure it's empty.🧰 Tools
🪛 golangci-lint (1.64.8)
10-10: unnecessary leading newline
(whitespace)
73-73: unnecessary trailing newline
(whitespace)
|
@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< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/internal/function_test.go (2)
13-13: Remove unnecessary leading newline.The static analysis tool correctly identifies an unnecessary leading newline.
func TestCheckFileNameValidity(t *testing.T) { - tests := []struct {🧰 Tools
🪛 golangci-lint (1.64.8)
13-13: unnecessary leading newline
(whitespace)
66-71: Improve assertion style for better readability.The test logic using testify is much improved from previous versions. However, the static analysis tool suggests using
assert.Containsfor better readability.if !tt.wantErr { require.NoError(t, err) } else { require.Error(t, err) - assert.True(t, strings.Contains(err.Error(), tt.errMsg)) + assert.Contains(t, err.Error(), tt.errMsg) }🧰 Tools
🪛 golangci-lint (1.64.8)
70-70: contains: use assert.Contains
(testifylint)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/internal/common/style.go(2 hunks)src/internal/function.go(2 hunks)src/internal/function_test.go(1 hunks)src/internal/handle_modal.go(1 hunks)src/internal/model_file_operations_test.go(2 hunks)src/internal/model_render.go(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/internal/common/style.go
🚧 Files skipped from review as they are similar to previous changes (4)
- src/internal/function.go
- src/internal/model_file_operations_test.go
- src/internal/handle_modal.go
- src/internal/model_render.go
🧰 Additional context used
🪛 golangci-lint (1.64.8)
src/internal/function_test.go
70-70: contains: use assert.Contains
(testifylint)
13-13: unnecessary leading newline
(whitespace)
🔇 Additional comments (3)
src/internal/function_test.go (3)
9-10: LGTM! Testify imports properly added.The testify imports have been correctly added as requested in previous reviews, following the standard pattern used across the codebase.
21-59: Excellent test case coverage.The test cases comprehensively cover both valid and invalid filename scenarios, including platform-specific path separators and edge cases. The error messages are consistent and informative.
34-34:✅ Verification successful
Verify error message format consistency.
Ensure that the dynamic error messages using
fmt.Sprintfmatch the actual error messages returned by thecheckFileNameValidityfunction implementation.Also applies to: 39-39
🏁 Script executed:
#!/bin/bash # Description: Verify the actual error messages returned by checkFileNameValidity function # Expected: Error messages should match the test expectations echo "Searching for checkFileNameValidity function implementation:" ast-grep --pattern 'func checkFileNameValidity($name) error { $$$ }' echo -e "\nSearching for error message patterns:" rg "file name cannot end with" --type go -A 2 -B 2Length of output: 1583
Error message formats are consistent – no changes needed.
Both the implementation in
src/internal/function.goand the test expectations insrc/internal/function_test.gouse the identical format string:"file name cannot end with '%c.' or '%c..'"and pass
filepath.Separatortwice, so the test’serrMsgmatches the actual error returned bycheckFileNameValidity.
|
@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 |
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? |
417a383 to
93a51ad
Compare
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [yorukot/superfile](https://github.com/yorukot/superfile) | patch | `v1.3.1` -> `v1.3.3` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>yorukot/superfile (yorukot/superfile)</summary> ### [`v1.3.3`](https://github.com/yorukot/superfile/releases/tag/v1.3.3) [Compare Source](yorukot/superfile@v1.3.2...v1.3.3) Hey folks. Releasing v1.3.3 with bug fix related to config file, and improvements in metadata panel feature. #### Install: [**Click me to know how to install**](https://github.com/yorukot/superfile?tab=readme-ov-file#installation) #### Highlights - Fixed a bug in config file correction that would make config file invalid. Thanks [@​estebandpena](https://github.com/estebandpena) for reporting the issue, and [@​wassup05](https://github.com/wassup05) for the fix. #### Detailed Change Summary <details><summary>Details</summary> <p> ##### Update - feat: Metadata loading via bubbletea's tea.Cmd method, removed usage channels and custom goroutines [#​947](yorukot/superfile#947) by @​lazysegtree - feat: Metadata panel into separate package, UI bug fixes, Code improvements [#​950](yorukot/superfile#950) by @​lazysegtree - feat: add support for Python virtual environment in testsuite setup [#​956](yorukot/superfile#956) by @​Khitoshi ##### Bug fix - fix: windows test ci [#​941](yorukot/superfile#941) by @​claykom - fix: fixing `config.toml` [#​952](yorukot/superfile#952) by @​wassup05 </p> </details> **Full Changelog**: yorukot/superfile@v1.3.2...v1.3.3 ### [`v1.3.2`](https://github.com/yorukot/superfile/releases/tag/v1.3.2) [Compare Source](yorukot/superfile@v1.3.1...v1.3.2) Hey folks. Releasing v1.3.2 with multiple new features including implementation image preview using kitty protocol, and various bug fixes and internal improvements. ##### **You can now preview images in high quality — no more pixelation!** <img width="1267" height="670" alt="image" src="https://github.com/user-attachments/assets/0f7ec48e-9386-4716-92a5-4a02783f6612" /> #### Install: [**Click me to know how to install**](https://github.com/yorukot/superfile?tab=readme-ov-file#installation) #### Highlights - Added image preview via kitty protocol. Thanks @​JassonCordones and @​yorukot for the implementation. - Added Zoxide support for path resolution in initial configuration. Thanks @​yorukot for this. - New 0x96f Theme by @​filipjanevski - Various usability and layout bug fixes. See "Detailed Change Summary" below. Thanks to @​larsn03 @​Frost-Phoenix @​TheLazron @​vkhatsiur @​Khitoshi @​claykom ##### Developer Improvements - Added CI Action to run unit tests and build for windows. - Updated contribution guidelines and MR template - Added a dev.sh script for building, linting and running tests for faster development workflows. #### Detailed Change Summary <details><summary>Details</summary> <p> ##### Update - Normalize user-facing naming to superfile [#​880](yorukot/superfile#880) by @​yorukot - Add kitty protocol for image preview [#​841](yorukot/superfile#841) by @​JassonCordones - feat: add Zoxide support for path resolution in initial configuration [#​892](yorukot/superfile#892) by @​yorukot - feat: update superfile's help output [#​908](yorukot/superfile#908) by @​yorukot - feat: Add Action to Publish to Winget [#​925](yorukot/superfile#925) by @​claykom - feat: update superfile build test for the windows and macOS [#​922](yorukot/superfile#922) by @​yorukot - Theme: add 0x96f theme [#​860](yorukot/superfile#860) by @​filipjanevski ##### Bug fix - fix: outdated and broken nix flake [#​846](yorukot/superfile#846) by @​Frost-Phoenix - fix: handle UTF-8 BOM in file reader [#​865](yorukot/superfile#865) by @​vkhatsiur - fix icon displayed on spf prompt when nerdfont disabled [#​878](yorukot/superfile#878) by @​claykom - fix: create item check for dot-entries [#​817](yorukot/superfile#817) by @​TheLazron - fix: prevent pasting a directory into itself, avoiding infinite loop [#​887](yorukot/superfile#887) by @​yorukot - fix: clear search bar value on parent directory reset [#​906](yorukot/superfile#906) by @​yorukot - fix: enhance terminal pixel detection and response handling [#​904](yorukot/superfile#904) by @​yorukot - fix: Cannot Build superfile on Windows [#​921](yorukot/superfile#921) by @​claykom - fix: Improve command tokenization to handle quotes and escapes [#​931](yorukot/superfile#931) by @​Khitoshi - fix: Dont read special files, and prevent freeze [#​932](yorukot/superfile#932) by @​lazysegtree - Compress all files selected [#​821](yorukot/superfile#821) by @​larsn03 ##### Optimization - Metadata and filepanel rendering refactor [#​867](yorukot/superfile#867) by @​JassonCordones - refactor: simplify panel mode handling in file movement logic [#​907](yorukot/superfile#907) by @​yorukot - refactor: standardize TODO comments and ReadMe to README [#​913](yorukot/superfile#913) by @​yorukot ##### Documentation - enhance: add detailed documentation for InitIcon function and update … [#​879](yorukot/superfile#879) by @​yorukot - docs: add documentation for image preview [#​882](yorukot/superfile#882) by @​yorukot - docs: update contributing guide and MR template [#​885](yorukot/superfile#885) by @​yorukot - docs: update README and plugin documentation for clarity and structure [#​902](yorukot/superfile#902) by @​yorukot - feat(docs): Update arch install package docs [#​929](yorukot/superfile#929) by @​booth-w ##### CI/CD - ci: add MR title linting with semantic-pull-request action [#​884](yorukot/superfile#884) by @​yorukot - ci: improve MR workflows with contributor greeting and title linter fix [#​886](yorukot/superfile#886) by @​yorukot ##### Dependencies - build(deps): bump prismjs from 1.29.0 to 1.30.0 in /website [#​786](yorukot/superfile#786) by @​dependabot[bot] - fix(deps): update dependency astro to v5.8.0 [#​787](yorukot/superfile#787) by @​renovate[bot] - chore(deps): bump vite from 6.3.3 to 6.3.5 in /website [#​822](yorukot/superfile#822) by @​dependabot[bot] - fix(deps): update dependency sharp to v0.34.2 [#​909](yorukot/superfile#909) by @​renovate[bot] - fix(deps): update astro monorepo [#​894](yorukot/superfile#894) by @​renovate[bot] - fix(deps): update fontsource monorepo to v5.2.6 [#​910](yorukot/superfile#910) by @​renovate[bot] ##### Misc - chore(license): update copyright year [#​895](yorukot/superfile#895) by @​yorukot - feat: add ignore missing field flag [#​881](yorukot/superfile#881) by @​claykom - feat: add sitemap integration and update giscus input position [#​912](yorukot/superfile#912) by @​yorukot </p> </details> #### New Contributors * @​filipjanevski made their first contribution in yorukot/superfile#860 * @​larsn03 made their first contribution in yorukot/superfile#821 * @​vkhatsiur made their first contribution in yorukot/superfile#865 * @​claykom made their first contribution in yorukot/superfile#878 * @​TheLazron made their first contribution in yorukot/superfile#817 * @​Khitoshi made their first contribution in yorukot/superfile#931 **Full Changelog**: yorukot/superfile@v1.3.1...v1.3.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC42Mi4xIiwidXBkYXRlZEluVmVyIjoiNDAuNjIuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Solves #566
Solution
Added util function to check for the cases where name:
.or../.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