Permalink
Browse files

issue10 - dot slash urls

  • Loading branch information...
1 parent 025498b commit 2786c696977048e0333bd9cefde74cc6c16eed09 @peterbe committed Feb 13, 2013
Showing with 50 additions and 15 deletions.
  1. +6 −0 docs/changelog.rst
  2. +1 −1 mincss/__init__.py
  3. +4 −14 mincss/processor.py
  4. +39 −0 tests/test_mincss.py
View
@@ -5,6 +5,12 @@
Changelog
=========
+v0.7.0 (2013-02-13)
+-------------------
+
+Fixed bug with make absolute url of url like `http://peterbe.com` +
+`./style.css`. Thanks @erfaan!
+
v0.6.1 (2013-02-12)
-------------------
View
@@ -1 +1 @@
-__version__ = '0.6.1'
+__version__ = '0.7.0'
View
@@ -170,7 +170,7 @@ def process_html(self, html, url):
link.attrib.get('rel', '') == 'stylesheet' or
link.attrib['href'].lower().split('?')[0].endswith('.css')
):
- link_url = self._make_absolute_url(url, link.attrib['href'])
+ link_url = self.make_absolute_url(url, link.attrib['href'])
key = (link_url, link.attrib['href'])
self.blocks[key] = self._download(link_url)
if self.preserve_remote_urls:
@@ -418,19 +418,9 @@ def __found(self, bodies, selector):
print >>sys.stderr, repr(selector)
return False
- def _make_absolute_url(self, url, href):
- parsed = urlparse.urlparse(url)
- if href.startswith('//'):
- return parsed.scheme + ':' + href
- if href.startswith('/'):
- return parsed.scheme + '://' + parsed.netloc + href
- if href.count('://'):
- return href
- path = parsed.path
- parts = path.split('/')
- parts[-1] = href
- path = '/'.join(parts)
- return parsed.scheme + '://' + parsed.netloc + path
+ @staticmethod
+ def make_absolute_url(url, href):
+ return urlparse.urljoin(url, href)
class _Result(object):
View
@@ -221,3 +221,42 @@ def test_download_with_phantomjs(self):
'''
for i, line in enumerate(expect.strip().splitlines()):
eq_(line.strip(), lines_after[i].strip())
+
+ def test_make_absolute_url(self):
+ p = Processor()
+ eq_(
+ p.make_absolute_url('http://www.com/', './style.css'),
+ 'http://www.com/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com', './style.css'),
+ 'http://www.com/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com', '//cdn.com/style.css'),
+ 'http://cdn.com/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com/', '//cdn.com/style.css'),
+ 'http://cdn.com/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com/', '/style.css'),
+ 'http://www.com/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com/elsewhere', '/style.css'),
+ 'http://www.com/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com/elsewhere/', '/style.css'),
+ 'http://www.com/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com/elsewhere/', './style.css'),
+ 'http://www.com/elsewhere/style.css'
+ )
+ eq_(
+ p.make_absolute_url('http://www.com/elsewhere', './style.css'),
+ 'http://www.com/style.css'
+ )

0 comments on commit 2786c69

Please sign in to comment.