8000 Add url to validation by fabaff · Pull Request #2874 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add url to validation #2874

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 3 commits into from
Aug 19, 2016
Merged

Add url to validation #2874

merged 3 commits into from
Aug 19, 2016

Conversation

fabaff
Copy link
Member
@fabaff fabaff commented Aug 18, 2016

Description:
Shortcut for the validation of URLs. voluptuous is using urllib.parse to validate an URL but I think that we should be more restrictive and only allow http/https as htp will definitely not lead to a success.

>>> import voluptuous as vol
>>> vol.Schema(vol.Url())('htp://localhost')
'htp://localhost'
>>> from urllib.parse import urlparse
>>> urlparse('htp://localhost')
ParseResult(scheme='htp', netloc='localhost', path='', params='', query='', fragment='')

Schemas for REST/aREST could benefit from this.

Related issue (if applicable): fixes #2800

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@robbiet480
Copy link
Member

I assume this came out of the vol.Url() usage in notify.html5? Either way, all for it!

@@ -255,6 +256,17 @@ def time_zone(value):
weekdays = vol.All(ensure_list, [vol.In(WEEKDAYS)])


def url(value: Any) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not call it url, as a url can contain any protocol. Let's call it http_url

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, although it can obviously also be https…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine as url. The definition of URL is that it is a universal resource locator, not something specifically made for HTTP(S) only. And it keeps our existing syntax of cv.string, cv.bool, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url is correct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok let's do url.

@balloob
Copy link
Member
balloob commented Aug 19, 2016

Good to merge when linting passes 👍

@fabaff fabaff merged commit ca1de9c into home-assistant:dev Aug 19, 2016
@fabaff fabaff deleted the url branch August 19, 2016 11:41
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use voluptuous
4 participants
0