LInk validation of url includes https, http,localhost and ip address using regex library of python
This will always return value. You should run it against some tests. Probably Django's itself since this is from v1.3. You should look at v1.11's validator - it seems to cover a lot more cases (specific IPv4/6 checks instead of just digits, internationalized domain names containing unicode characters etc)
value
@shaily Thank you, I am working on this :)
A few comments: - It does not seem to be actually checking the value, you're compiling the regex but not using it - Please remove the TODO comment. - The regex could be compiled outside of the function definition, so it's compiled once at import time and not on each call (which is faster) - Please provide unit tests.
TODO
1 new commit added
In hubs.tests.test_widget_validators the default test for link is def test_link(self): value = '<a href="somewhere">dummy</a>' self.assertEqual(validators.Link.from_string(value), value) self.assertRaises(ValueError, validators.Link, "text") I am not sure , that do we need to provide value as a string of words also containing a link or simply a link we need to verify like 'http://example.com'.
def test_link(self): value = '<a href="somewhere">dummy</a>' self.assertEqual(validators.Link.from_string(value), value) self.assertRaises(ValueError, validators.Link, "text")
To answer that question, I looked at where this validator is used. Apparently it's only used in the rules widget, and the filed only contains the URL, not the HTML <a href=...></a> tag. So validating an URL should be sufficient.
rules
<a href=...></a>
For validation, I think that using re.match is more appropriate than re.search.
re.match
re.search
is this one still being worked on?
Pull-Request has been closed by ryanlerch
LInk validation of url includes https, http,localhost and ip address using regex library of python