Skip to content

Commit 0f890cf

Browse files
committed
fixed is_url
1 parent a7b90db commit 0f890cf

File tree

14 files changed

+40
-26
lines changed

14 files changed

+40
-26
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Python String Utils Changelog
22

3+
## v0.4.2
4+
5+
### Fixed:
6+
- is_url
7+
38
## v0.4.1
49

510
### Changed:
611
- is_palindrome and is_pangram now return False if the given object is not a string instead of raising an exception
712

8-
913
## v0.4.0
1014

1115
### Added:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Davide Zanotti
3+
Copyright (c) 2016 Davide Zanotti
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
-87 Bytes
Binary file not shown.

docs/_build/doctrees/index.doctree

-1.63 KB
Binary file not shown.

docs/_build/html/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 570d49f719075ab443795a1c37a0913b
3+
config: 25835ebf44df34ab4dfcc31a3df693bc
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

docs/_build/html/genindex.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1111

12-
<title>Index &mdash; Python String Utils 0.4.1 documentation</title>
12+
<title>Index &mdash; Python String Utils 0.4.2 documentation</title>
1313

1414

1515

@@ -34,7 +34,7 @@
3434
<link rel="index" title="Index"
3535
href="#"/>
3636
<link rel="search" title="Search" href="search.html"/>
37-
<link rel="top" title="Python String Utils 0.4.1 documentation" href="index.html"/>
37+
<link rel="top" title="Python String Utils 0.4.2 documentation" href="index.html"/>
3838

3939

4040
<script src="_static/js/modernizr.min.js"></script>
@@ -62,7 +62,7 @@
6262

6363

6464
<div class="version">
65-
0.4.1
65+
0.4.2
6666
</div>
6767

6868

@@ -303,7 +303,7 @@ <h2 id="W">W</h2>
303303
<script type="text/javascript">
304304
var DOCUMENTATION_OPTIONS = {
305305
URL_ROOT:'./',
306-
VERSION:'0.4.1',
306+
VERSION:'0.4.2',
307307
COLLAPSE_INDEX:false,
308308
FILE_SUFFIX:'.html',
309309
HAS_SOURCE: true

docs/_build/html/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010

11-
<title>Welcome to Python String Utils’s documentation! &mdash; Python String Utils 0.4.1 documentation</title>
11+
<title>Welcome to Python String Utils’s documentation! &mdash; Python String Utils 0.4.2 documentation</title>
1212

1313

1414

@@ -33,7 +33,7 @@
3333
<link rel="index" title="Index"
3434
href="genindex.html"/>
3535
<link rel="search" title="Search" href="search.html"/>
36-
<link rel="top" title="Python String Utils 0.4.1 documentation" href="#"/>
36+
<link rel="top" title="Python String Utils 0.4.2 documentation" href="#"/>
3737

3838

3939
<script src="_static/js/modernizr.min.js"></script>
@@ -61,7 +61,7 @@
6161

6262

6363
<div class="version">
64-
0.4.1
64+
0.4.2
6565
</div>
6666

6767

@@ -628,7 +628,7 @@ <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Pe
628628
<script type="text/javascript">
629629
var DOCUMENTATION_OPTIONS = {
630630
URL_ROOT:'./',
631-
VERSION:'0.4.1',
631+
VERSION:'0.4.2',
632632
COLLAPSE_INDEX:false,
633633
FILE_SUFFIX:'.html',
634634
HAS_SOURCE: true

docs/_build/html/objects.inv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Sphinx inventory version 2
22
# Project: Python String Utils
3-
# Version: 0.4.1
3+
# Version: 0.4.2
44
# The remainder of this file is compressed using zlib.
55
xڝ��N! ���M<�ƽ�x0�dc<:3(_�E����;FcRo�����d�$3�".t� ��>v39{�l���;��w�r`�$�^�B=b�~ ��o�IO�x���� �K`&�@*`�<�2�M��_��XDT�(Rp������A�����m�crb�:g�yИ�Ȍ I��uw��8Z�U�:Nk�s貉�Yb�=$]�(dOS��"�����r�~/��U'�벻�t�h�x;�� � �%Щu�c��EA����,���O�5.��ю}h_\����0'���O�Tt��M݊

docs/_build/html/py-modindex.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010

11-
<title>Python Module Index &mdash; Python String Utils 0.4.1 documentation</title>
11+
<title>Python Module Index &mdash; Python String Utils 0.4.2 documentation</title>
1212

1313

1414

@@ -33,7 +33,7 @@
3333
<link rel="index" title="Index"
3434
href="genindex.html"/>
3535
<link rel="search" title="Search" href="search.html"/>
36-
<link rel="top" title="Python String Utils 0.4.1 documentation" href="index.html"/>
36+
<link rel="top" title="Python String Utils 0.4.2 documentation" href="index.html"/>
3737

3838

3939
<script type="text/javascript">
@@ -68,7 +68,7 @@
6868

6969

7070
<div class="version">
71-
0.4.1
71+
0.4.2
7272
</div>
7373

7474

@@ -181,7 +181,7 @@ <h1>Python Module Index</h1>
181181
<script type="text/javascript">
182182
var DOCUMENTATION_OPTIONS = {
183183
URL_ROOT:'./',
184-
VERSION:'0.4.1',
184+
VERSION:'0.4.2',
185185
COLLAPSE_INDEX:false,
186186
FILE_SUFFIX:'.html',
187187
HAS_SOURCE: true

docs/_build/html/search.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<meta name="viewport" content="width=device-width, initial-scale=1.0">
1010

11-
<title>Search &mdash; Python String Utils 0.4.1 documentation</title>
11+
<title>Search &mdash; Python String Utils 0.4.2 documentation</title>
1212

1313

1414

@@ -33,7 +33,7 @@
3333
<link rel="index" title="Index"
3434
href="genindex.html"/>
3535
<link rel="search" title="Search" href="#"/>
36-
<link rel="top" title="Python String Utils 0.4.1 documentation" href="index.html"/>
36+
<link rel="top" title="Python String Utils 0.4.2 documentation" href="index.html"/>
3737

3838

3939
<script src="_static/js/modernizr.min.js"></script>
@@ -61,7 +61,7 @@
6161

6262

6363
<div class="version">
64-
0.4.1
64+
0.4.2
6565
</div>
6666

6767

@@ -167,7 +167,7 @@
167167
<script type="text/javascript">
168168
var DOCUMENTATION_OPTIONS = {
169169
URL_ROOT:'./',
170-
VERSION:'0.4.1',
170+
VERSION:'0.4.2',
171171
COLLAPSE_INDEX:false,
172172
FILE_SUFFIX:'.html',
173173
HAS_SOURCE: true

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
# built documents.
5959
#
6060
# The short X.Y version.
61-
version = '0.4.1'
61+
version = '0.4.2'
6262
# The full version, including alpha/beta/rc tags.
63-
release = '0.4.1'
63+
release = '0.4.2'
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='python-string-utils',
8-
version='0.4.1',
8+
version='0.4.2',
99
description='Utility functions for strings checking and manipulation.',
1010
long_description=long_description,
1111
author='Davide Zanotti',

string_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import random
77

88
# module settings
9-
__version__ = '0.4.0'
9+
__version__ = '0.4.2'
1010
__all__ = [
1111
'is_string',
1212
'is_url',
@@ -36,7 +36,7 @@
3636
r'([a-z-]+://)' # scheme
3737
r'([a-z_\d-]+:[a-z_\d-]+@)?' # user:password
3838
r'(www\.)?' # www.
39-
r'((?<!\.)[a-z\d\.-]+\.[a-z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost)' # domain
39+
r'((?<!\.)[a-z\d]+[a-z\d\.-]+\.[a-z]{2,6}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|localhost)' # domain
4040
r'(:\d{2,})?' # port number
4141
r'(/[a-z\d_%\+-]*)*' # folders
4242
r'(\.[a-z\d_%\+-]+)*' # file extension

tests.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def test_domain_extension_should_be_between_2_and_6_letters(self):
5555

5656
def test_should_accept_any_scheme_by_default(self):
5757
self.assertTrue(is_url('http://site.com'))
58+
self.assertTrue(is_url('http://www.site.com'))
5859
self.assertTrue(is_url('https://site.com'))
60+
self.assertTrue(is_url('https://www.site.com'))
5961
self.assertTrue(is_url('ftp://site.com'))
6062
self.assertTrue(is_url('git://site.com'))
6163

@@ -64,7 +66,13 @@ def test_should_restrict_checking_on_provided_schemes(self):
6466
self.assertFalse(is_url('git://site.com', allowed_schemes=['http', 'https']))
6567

6668
def test_url_cannot_start_with_dot(self):
67-
self.assertTrue(is_url('http://.site.com'))
69+
self.assertFalse(is_url('http://.site.com'))
70+
71+
def test_url_can_contain_dash(self):
72+
self.assertTrue(is_url('http://some-site-name.com'))
73+
74+
def test_url_cannot_start_with_dash(self):
75+
self.assertFalse(is_url('http://-site.com'))
6876

6977
def test_url_cannot_start_with_slash(self):
7078
self.assertFalse(is_url('http:///www.site.com'))
@@ -92,6 +100,8 @@ def test_should_exclude_invalid_ip(self):
92100
self.assertFalse(is_url('http://123.123.123.1234'))
93101
self.assertFalse(is_url('http://.123.123.123.123'))
94102
self.assertFalse(is_url('http://123.123.123.123.'))
103+
self.assertFalse(is_url('http://123.123...123.123'))
104+
self.assertFalse(is_url('http://123..123..123.123'))
95105

96106
def test_url_can_have_port_number(self):
97107
self.assertTrue(is_url('http://localhost:8080'))

0 commit comments

Comments
 (0)