-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Fix up some of the logic around repo and submodule URLs #3860
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,11 @@ def __call__(self, value): | |
@deconstructible | ||
class RepositoryURLValidator(object): | ||
|
||
disallow_relative_url = True | ||
|
||
# Pattern for ``[email protected]:user/repo`` pattern | ||
re_git_user = re.compile(r'^[\w]+@.+') | ||
|
||
def __call__(self, value): | ||
allow_private_repos = getattr(settings, 'ALLOW_PRIVATE_REPOS', False) | ||
public_schemes = ['https', 'http', 'git', 'ftps', 'ftp'] | ||
|
@@ -60,28 +65,51 @@ def __call__(self, value): | |
if allow_private_repos: | ||
valid_schemes += private_schemes | ||
url = urlparse(value) | ||
if ( | ||
( # pylint: disable=too-many-boolean-expressions | ||
url.scheme not in valid_schemes and | ||
'@' not in value and | ||
not value.startswith('lp:') | ||
) or | ||
( | ||
value.startswith('/') or | ||
value.startswith('file://') or | ||
value.startswith('.') | ||
) | ||
): | ||
# Avoid ``/path/to/local/file`` and ``file://`` scheme but allow | ||
# ``[email protected]:user/project.git`` and ``lp:bazaar`` | ||
raise ValidationError(_('Invalid scheme for URL')) | ||
elif '&&' in value or '|' in value: | ||
|
||
# Malicious characters go first | ||
if '&&' in value or '|' in value: | ||
raise ValidationError(_('Invalid character in the URL')) | ||
elif ( | ||
('@' in value or url.scheme in private_schemes) and | ||
not allow_private_repos | ||
): | ||
raise ValidationError('Clonning via SSH is not supported') | ||
return value | ||
elif url.scheme in valid_schemes: | ||
return value | ||
|
||
# Repo URL is not a supported scheme at this point, but there are | ||
# several cases where we might support it | ||
# Launchpad | ||
elif value.startswith('lp:'): | ||
return value | ||
# Relative paths are conditionally supported | ||
elif value.startswith('.') and not self.disallow_relative_url: | ||
return value | ||
# SSH cloning and ``[email protected]:user/project.git`` | ||
elif self.re_git_user.search(value) or url.scheme in private_schemes: | ||
if allow_private_repos: | ||
return value | ||
else: | ||
# Throw a more helpful error message | ||
raise ValidationError('Manual cloning via SSH is not supported') | ||
|
||
# No more valid URLs without supported URL schemes | ||
raise ValidationError(_('Invalid scheme for URL')) | ||
|
||
|
||
class SubmoduleURLValidator(RepositoryURLValidator): | ||
|
||
""" | ||
A URL validator for repository submodules | ||
|
||
If a repository has a relative submodule, the URL path is effectively the | ||
supermodule's remote ``origin`` URL with the relative path applied. | ||
|
||
From the git docs:: | ||
|
||
``<repository>`` is the URL of the new submodule's origin repository. | ||
This may be either an absolute URL, or (if it begins with ``./`` or | ||
``../``), the location relative to the superproject's default remote | ||
repository | ||
""" | ||
|
||
disallow_relative_url = False | ||
|
||
|
||
validate_repository_url = RepositoryURLValidator() | ||
validate_submodule_url = SubmoduleURLValidator() |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
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.
Now this
invalidsubmodule
is no more invalid.We probably need to remove this.