Merge lp:~benji/landscape-charm/bug-1411677-license-parsing-does-not-handle-extra-newline into lp:~landscape/landscape-charm/trunk

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: 220
Merged at revision: 219
Proposed branch: lp:~benji/landscape-charm/bug-1411677-license-parsing-does-not-handle-extra-newline
Merge into: lp:~landscape/landscape-charm/trunk
Diff against target: 52 lines (+25/-0)
3 files modified
.bzrignore (+1/-0)
hooks/hooks.py (+4/-0)
hooks/test_hooks.py (+20/-0)
To merge this branch: bzr merge lp:~benji/landscape-charm/bug-1411677-license-parsing-does-not-handle-extra-newline
Reviewer Review Type Date Requested Status
David Britton (community) Approve
Björn Tillenius (community) Approve
Review via email: mp+247055@code.launchpad.net

Commit message

Fix license URL recognition in the face of leading/trailing whitespace.

Description of the change

This is a simple fix for bug 1411677 (license URL with leading/trailing newline is not recognized).

To post a comment you must log in.
220. By Benji York

tweak docstrings

Revision history for this message
Björn Tillenius (bjornt) wrote :

Looks good, +1

review: Approve
Revision history for this message
David Britton (dpb) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2014-12-10 22:45:09 +0000
3+++ .bzrignore 2015-01-20 18:15:26 +0000
4@@ -1,1 +1,2 @@
5 _trial_temp
6+tags
7
8=== modified file 'hooks/hooks.py'
9--- hooks/hooks.py 2015-01-19 18:05:58 +0000
10+++ hooks/hooks.py 2015-01-20 18:15:26 +0000
11@@ -570,6 +570,10 @@
12 if not license_file:
13 juju.juju_log("No license file given, skipping")
14 return
15+ else:
16+ # Leading or trailing whitespace is nonsensical, so remove it.
17+ license_file = license_file.strip()
18+
19 if re.match(license_file_re, license_file):
20 license_file = _download_file(license_file)
21
22
23=== modified file 'hooks/test_hooks.py'
24--- hooks/test_hooks.py 2015-01-19 19:29:44 +0000
25+++ hooks/test_hooks.py 2015-01-20 18:15:26 +0000
26@@ -994,6 +994,26 @@
27 self.assertFileContains(
28 hooks.LANDSCAPE_LICENSE_DEST, "LICENSE_FILE_TEXT from curl")
29
30+ def test__install_license_url_with_trailing_whitespace(self):
31+ """Install a license from a url with trailing whitespace."""
32+ source = self.makeFile()
33+ with open(source, "w") as fp:
34+ fp.write("LICENSE_FILE_TEXT from curl")
35+ hooks.juju.config["license-file"] = "file:///%s\n\n\n" % source
36+ hooks._install_license()
37+ self.assertFileContains(
38+ hooks.LANDSCAPE_LICENSE_DEST, "LICENSE_FILE_TEXT from curl")
39+
40+ def test__install_license_url_with_leading_whitespace(self):
41+ """Install a license from a url with leading whitespace."""
42+ source = self.makeFile()
43+ with open(source, "w") as fp:
44+ fp.write("LICENSE_FILE_TEXT from curl")
45+ hooks.juju.config["license-file"] = "\n\n\nfile:///%s" % source
46+ hooks._install_license()
47+ self.assertFileContains(
48+ hooks.LANDSCAPE_LICENSE_DEST, "LICENSE_FILE_TEXT from curl")
49+
50 def test_handle_no_license(self):
51 """Don't try to install the license when none was given."""
52 hooks.juju.config["license-file"] = None

Subscribers

People subscribed via source and target branches