-
Notifications
You must be signed in to change notification settings - Fork 35
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 folder spec for plugin filename regex #632
Open
andrewhand
wants to merge
2
commits into
dev
Choose a base branch
from
fix-folder-spec-for-plugin-filename-regex
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here's a Python test file that contains the regex that seems to handle most cases, as well as tests to run. EDIT: I added a couple of additional tests in import re
python_filepath_pattern = r'^(?!.*/_)(?!_/)([a-zA-Z][a-zA-Z0-9_]*/)*[a-zA-Z_][a-zA-Z0-9_]*(?<!_)\.py$'
def validate_python_filepath(filepath):
return re.match(python_filepath_pattern, filepath) is not None
# Valid paths (for reference)
valid_paths = [
r'hello.py',
r'hello_world.py',
r'hello_world/main.py',
r'package/sub_package/module.py',
r'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p.py', # Many nested directories
r'_underscore_start.py',
]
# Invalid paths (expanded)
invalid_paths = [
r'hello world.py', # Space in filename
r'3ight/hello.py', # Directory starting with a number
r'hello_world//main.py', # Double slash
r'module.py.txt', # Wrong extension
r'/absolute/path.py', # Absolute path
r'.py', # Just the extension
r'hello.py/', # Ends with a slash
r'/hello.py', # Starts with a slash
r'hello..py', # Double dot in extension
r'hello.py.py', # Double .py extension
r'hello_.py', # Ends with underscore before extension
r'_/hello.py', # Single underscore directory name
r'hello/_.py', # Single underscore filename
r'hello/_file.py', # Underscore start in nested file
r'HELLO.PY', # Uppercase extension (assuming case-sensitive)
r'hello.pY', # Mixed case extension
r'hello/world/.py', # Hidden file in nested directory
r'hello/.world/file.py', # Hidden directory
r' hello.py', # Leading space
r'hello.py ', # Trailing space
r'\thello.py', # Tab character
r'hello\world.py', # Backslash instead of forward slash
r'hello:world.py', # Invalid character (colon)
r'hello@world.py', # Invalid character (at sign)
r'hello/world.py/extra', # Extra content after .py
r'', # Empty string
r'hello/', # Directory without file
r'hello.py/world.py', # .py in middle of path
r'1/2/3/4.py', # All numeric directory names
r'../sample.py', # No relative paths
r'..sample.py', # No prefix with dots
]
# Test all paths
for path in valid_paths + invalid_paths:
result = 'Valid' if validate_python_filepath(path) else 'Invalid'
print(f"{path}: {result}") Here's the output when you run the above:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed bug where API would not except plugin filenames as a directory and added test to support.