-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Check for invalid characters prior to rename #5193
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -558,6 +558,10 @@ def rename_file(self, old_path, new_path): | |
| if new_path == old_path: | ||
| return | ||
|
|
||
| # Perform path validation prior to converting to os-specific value since this | ||
| # is still relative to root_dir. | ||
| self._validate_path(new_path) | ||
|
|
||
| new_os_path = self._get_os_path(new_path) | ||
| old_os_path = self._get_os_path(old_path) | ||
|
|
||
|
|
@@ -586,3 +590,22 @@ def get_kernel_path(self, path, model=None): | |
| else: | ||
| parent_dir = '' | ||
| return parent_dir | ||
|
|
||
| @staticmethod | ||
| def _validate_path(path): | ||
| """Checks if the path contains invalid characters relative to the current platform""" | ||
|
|
||
| if sys.platform == 'win32': | ||
| # On Windows systems, we MUST disallow colons otherwise an Alternative Data Stream will | ||
| # be created and confusion will reign! (See https://github.com/jupyter/notebook/issues/5190) | ||
| # Go ahead and add other invalid (and non-path-separator) characters here as well so there's | ||
| # consistent behavior - although all others will result in '[Errno 22]Invalid Argument' errors. | ||
| invalid_chars = (':', '>', '<', '*', '?', '|', '"') | ||
| else: | ||
| # On non-windows systems, allow the underlying file creation to perform enforcement when appropriate | ||
| invalid_chars = () | ||
kevin-bates marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for char in invalid_chars: | ||
| if char in path: | ||
| raise web.HTTPError(400, u"Path '{}' contains invalid characters {} relative to its platform. " | ||
|
||
| u"Please edit the path and re-submit the request.".format(path, invalid_chars)) | ||

Uh oh!
There was an error while loading. Please reload this page.