Permalink
Browse files

Improve url normalization for edge cases (bug 841093)

  • Loading branch information...
1 parent 5f1f59f commit 16e72d5490c2a913c6519f819ff41945fdf010a3 @mattbasta committed Feb 13, 2013
Showing with 32 additions and 1 deletion.
  1. +5 −1 appvalidator/testcases/webappbase.py
  2. +27 −0 tests/test_webapp_resources.py
@@ -86,8 +86,12 @@ def try_get_data_uri(data_url):
def _normalize_url(err, url):
+ manifest_url = err.get_resource("manifest_url")
+ if not manifest_url:
+ return url
+
p_url = urlparse.urlparse(url)
- p_defurl = urlparse.urlparse(err.get_resource("manifest_url"))
+ p_defurl = urlparse.urlparse(manifest_url)
return urlparse.urlunparse(p_defurl[:2] + p_url[2:])
@@ -333,3 +333,30 @@ def test_not_square(self):
def test_bad_size(self):
self._test_icon("icon-128.png", 256)
self.assert_failed(with_errors=True)
+
+
+class TestURLNormalizer(TestCase):
+ """Test that URLs are normalized properly."""
+
+ def setUp(self):
+ super(TestURLNormalizer, self).setUp()
+ self.setup_err()
+ self.err.save_resource("manifest_url", "https://foo.bar/zip/zap.htm")
+
+ def url(self, input, expected):
+ def wrap():
+ self.setUp()
+ normalized = appbase._normalize_url(self.err, input)
+ eq_(normalized, expected)
+ return wrap
+
+ def test_urls(self):
+ yield self.url("path/file.txt", "https://foo.bar/path/file.txt")
+ yield self.url("/path/file.txt", "https://foo.bar/path/file.txt")
+ yield self.url("file.txt", "https://foo.bar/file.txt")
+ yield self.url("/file.txt", "https://foo.bar/file.txt")
+ yield self.url("http://nice.try/asdf", "https://foo.bar/asdf")
+
+ def test_nulls(self):
+ self.err.save_resource("manifest_url", None)
+ eq_(appbase._normalize_url(self.err, '/foo.txt'), '/foo.txt')

0 comments on commit 16e72d5

Please sign in to comment.