Skip to content
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

Domain: fix form #7502

Merged
merged 4 commits into from Sep 28, 2020
Merged

Domain: fix form #7502

merged 4 commits into from Sep 28, 2020

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Sep 22, 2020

  • Allow to save the same domain with canonical=true
  • Don't save domains like domain.com/foo

- Allow to save the same domain with canonical=true
- Don't save domains like `domain.com/foo`
@stsewd stsewd requested a review from a team Sep 22, 2020
Copy link
Contributor

@agjohnson agjohnson left a comment

Looks good, i only had some minor improvements to suggest to make this more defensive.

if not parsed.scheme:
parsed = urlparse(f'https://{domain}')

if not parsed.netloc:
Copy link
Contributor

@agjohnson agjohnson Sep 22, 2020

Choose a reason for hiding this comment

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

This is much better than nothing, but it isn't a great check:

In [13]: parse.urlparse('https://*****.laksdhg.foo')
Out[13]: ParseResult(scheme='https', netloc='*****.laksdhg.foo', path='', params='', query='', fragment='')

Copy link
Member Author

@stsewd stsewd Sep 23, 2020

Choose a reason for hiding this comment

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

Looks like something the domain validator should be catching

domain_regex = (
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}(?<!-)\.?)|'
r'localhost|' # localhost...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4
r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6
)
@deconstructible
class DomainNameValidator(RegexValidator):

But isn't... Somehow that regex is allowing that value, I took at look at the new version of that validator https://github.com/django/django/pull/7300/files but the result is the same. Also, I think we shouldn't allow ip values here

readthedocs/projects/forms.py Outdated Show resolved Hide resolved
)
self.assertTrue(form.is_valid())
domain = form.save()
self.assertEqual(domain.domain, 'domain.com')
Copy link
Contributor

@agjohnson agjohnson Sep 22, 2020

Choose a reason for hiding this comment

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

It might be worth adding some test cases with more garbage data as well too

Copy link
Member Author

@stsewd stsewd Sep 23, 2020

Choose a reason for hiding this comment

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

I have added some, but mostly aren't being caught by https://github.com/readthedocs/readthedocs.org/pull/7502/files#r493113673

stsewd and others added 2 commits Sep 22, 2020
Co-authored-by: Anthony <aj@ohess.org>
Co-authored-by: Manuel Kaufmann <humitos@gmail.com>
@stsewd stsewd requested a review from agjohnson Sep 23, 2020
Copy link
Member

@ericholscher ericholscher left a comment

This looks good to me as a start at least. 👍

@stsewd stsewd merged commit 2e348f0 into master Sep 28, 2020
2 checks passed
@stsewd stsewd deleted the fix-domain-form branch Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants