Skip to content

Commit

Permalink
Merge remote-tracking branch 'kevin/validate-extension-name'
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed Aug 6, 2019
2 parents 0b4df6c + cda8aaa commit 009ffde
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,21 @@ class method. This method can be set as a entry_point in

@default("extension_name")
def _default_extension_name(self):
raise Exception("The extension must be given a `name`.")
raise ValueError("The extension must be given a `name`.")

@validate("extension_name")
def _valid_extension_name(self, obj, value):
if isinstance(name, str):
INVALID_EXTENSION_NAME_CHARS = [' ', '.', '+', '/']

def _validate_extension_name(self):
value = self.extension_name
if isinstance(value, str):
# Validate that extension_name doesn't contain any invalid characters.
for char in [' ', '.', '+', '/']:
self.error(obj, value)
for c in ExtensionApp.INVALID_EXTENSION_NAME_CHARS:
if c in value:
raise ValueError("Extension name '{name}' cannot contain any of the following characters: "
"{invalid_chars}.".
format(name=value, invalid_chars=ExtensionApp.INVALID_EXTENSION_NAME_CHARS))
return value
self.error(obj, value)
raise ValueError("Extension name must be a string, found {type}.".format(type=type(value)))

# Extension can configure the ServerApp from the command-line
classes = [
Expand Down Expand Up @@ -235,11 +240,12 @@ def initialize(self, serverapp, argv=[]):
- Passes settings to webapp
- Appends handlers to webapp.
"""
self._validate_extension_name()
# Initialize the extension application
super(ExtensionApp, self).initialize(argv=argv)
self.serverapp = serverapp

# Intialize config, settings, templates, and handlers.
# Initialize config, settings, templates, and handlers.
self._prepare_config()
self._prepare_templates()
self._prepare_settings()
Expand Down

0 comments on commit 009ffde

Please sign in to comment.