Skip to content

Fixing issue number #283 "New Project creation has "The project name should not contain space between them" even though there is no space. #283" #373

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

Anupkumarpandey1
Copy link
Contributor

Related Issues

Closes: #283

Problem Statement

Users on Ubuntu 20.04, Windows 11 (64-bit), and other OS versions were encountering a false positive validation error:

"The project name should not contain space between them"

This error occurred even when the project name itself did not contain any spaces. The issue was causing:

  • User frustration and confusion
  • Blocking of legitimate project creation attempts
  • Inconsistent behavior across different operating systems

Root Cause Analysis

The validation logic in Validation.py was incorrectly checking the entire project path (projDir) for whitespace instead of only the project name. This meant that if any parent directory in the path contained spaces (which is common in paths like /home/user name/Documents/), the validation would fail even for valid project names.

Solution Overview

This PR implements a targeted fix to resolve the validation issue:

Fixed Validation Logic in Validation.py

Before (Problematic Code):

# Checked entire path including parent directories
if re.search(r"\s", projDir):
    return "CHECKNAME"

After (Fixed Code):

# Extract only the project folder name and check for whitespace
projName = os.path.basename(projDir)
if re.search(r"\s", projName):
    return "CHECKNAME"

Impact: This dual approach ensures:

  1. Validation only checks the actual project name (projName) for spaces, not the full path with parent directories (projDir)
  2. Even if users enter spaces in their project names, those spaces are automatically replaced with underscores (_) instead of throwing a validation error
  3. Users get a seamless experience while maintaining clean, filesystem-friendly project names

Enhanced Input Sanitization in newProject.py

Before (Limited Handling):

# Only removed leading/trailing spaces
self.projName = str(self.projName).rstrip().lstrip()

After (Comprehensive Sanitization):

# Remove leading and trailing spaces AND replace internal spaces with underscores
self.projName = str(self.projName).strip().replace(" ", "_")

How This Addresses the Problem

Eliminates False Positives

  • Validation now correctly focuses only on the project name, not parent directory paths
  • Users with spaces in their system paths (e.g., "Program Files", "User Name") can now create projects successfully

Improves User Experience

  • Automatic space-to-underscore conversion prevents validation errors
  • Even if a user enters spaces in the project name, they will be automatically replaced with underscores (_) instead of throwing an error
  • Users don't need to manually avoid spaces in project names
  • Consistent behavior across all operating systems

Maintains Data Integrity

  • Project names still follow naming conventions (no spaces in final names)
  • Validation remains active for genuinely problematic characters
  • Backward compatibility with existing projects is preserved

Testing Performed

  • Tested on Ubuntu 20.04 with paths containing spaces
  • Tested on Windows 11 with "Program Files" and user directories containing spaces
  • Verified project creation works with various input combinations
  • Confirmed existing validation for other invalid characters still works
  • Tested automatic space replacement functionality

Files Modified

  1. src/projManagement/Validation.py - Fixed validation logic to check only project name
    • 5 additions, 2 deletions - Added projName = os.path.basename(projDir) and updated validation check
  2. src/projManagement/newProject.py - Enhanced input sanitization with space replacement
    • 3 additions, 1 deletion - Replaced rstrip().lstrip() with strip().replace(" ", "_")

Breaking Changes

None. This is a backward-compatible fix that only resolves the false positive issue without changing the core functionality.

Additional Notes

This fix resolves the core validation issue while maintaining the spirit of the original validation rule. Project names will still be clean and filesystem-friendly, but users will no longer encounter false validation errors due to their system's directory structure.

The changes are minimal and focused, addressing the specific issue without introducing unnecessary complexity or dependencies.

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.

1 participant