Skip to content

fix: prevent 'cd ..' from moving above root directory#36

Merged
anshumanjadiya1102 merged 2 commits intoDrive-for-Java:mainfrom
Harushii16:fix/cd-root-bug
Oct 14, 2025
Merged

fix: prevent 'cd ..' from moving above root directory#36
anshumanjadiya1102 merged 2 commits intoDrive-for-Java:mainfrom
Harushii16:fix/cd-root-bug

Conversation

@Harushii16
Copy link
Contributor

Summary #35

This PR improves the CdCommand in MyCMD to prevent users from navigating above the root directory. Now, when users execute cd .. at the root, the shell correctly prevents moving further up and shows a clear message.

Changes

  • Prevents moving above the root directory.
  • Handles relative paths correctly.
  • Fully compatible with the existing MyCMD shell.

Notes

  • This fix currently supports cd .. (with space).
  • The command cd.. (without space) is not affected because the shell does not parse it separately. Supporting it would require changes to the core input parser.

Motivation

Currently, executing cd .. at the root directory could cause unexpected behavior. This fix ensures the shell behaves reliably, preventing potential user errors and improving usability.

Hacktoberfest 2025

This contribution is submitted as part of Hacktoberfest 2025. 🎉
Excited to contribute and improve open-source software!

@anshumanjadiya1102 anshumanjadiya1102 added bug Something isn't working hacktoberfest-accepted This is for Hacktoberfest hacktoberfest This is for Hacktoberfest labels Oct 13, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the CdCommand to prevent users from navigating above the root directory when using cd .., improving shell reliability and user experience.

  • Adds root directory boundary checking to prevent navigation above filesystem root
  • Implements special handling for cd .. command with clear user feedback
  • Includes workaround for cd.. (without space) command parsing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@anshumanjadiya1102
Copy link
Member

@Harushii16, Please view above suggestions given by Copilot.

@Harushii16
Copy link
Contributor Author

I have resolved the copilot suggestions.

@anshumanjadiya1102
Copy link
Member

OK @Harushii16, I will merge it. And I have also invited you to our Organization. Join to Become a team member.

@anshumanjadiya1102 anshumanjadiya1102 merged commit e31dfbd into Drive-for-Java:main Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hacktoberfest This is for Hacktoberfest hacktoberfest-accepted This is for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants