1 |
thx Zac, I would never have figured that out myself |
2 |
|
3 |
the updated patch: |
4 |
|
5 |
From c703875bebd82271921d7e94b7cd61936b87d32b Mon Sep 17 00:00:00 2001 |
6 |
From: Wim Muskee <wimmuskee@×××××.com> |
7 |
Date: Sat, 7 Jan 2017 12:02:41 +0100 |
8 |
Subject: [PATCH] repoman: add HOMEPAGE.missingurischeme check |
9 |
|
10 |
--- |
11 |
.../pym/repoman/modules/scan/metadata/ebuild_metadata.py | 13 +++++++++++-- |
12 |
repoman/pym/repoman/qa_data.py | 2 ++ |
13 |
2 files changed, 13 insertions(+), 2 deletions(-) |
14 |
|
15 |
diff --git a/repoman/pym/repoman/modules/scan/metadata/ebuild_metadata.py |
16 |
b/repoman/pym/repoman/modules/scan/metadata/ebuild_metadata.py |
17 |
index e991a30..0a29d02 100644 |
18 |
--- a/repoman/pym/repoman/modules/scan/metadata/ebuild_metadata.py |
19 |
+++ b/repoman/pym/repoman/modules/scan/metadata/ebuild_metadata.py |
20 |
@@ -10,9 +10,10 @@ |
21 |
|
22 |
from repoman.modules.scan.scanbase import ScanBase |
23 |
from repoman.qa_data import missingvars |
24 |
+from repoman,_portage import portage |
25 |
|
26 |
NON_ASCII_RE = re.compile(r'[^\x00-\x7f]') |
27 |
- |
28 |
+URISCHEME_RE = re.compile(r'^[a-z][0-9a-z\-\.\+]+://') |
29 |
|
30 |
class EbuildMetadata(ScanBase): |
31 |
|
32 |
@@ -62,10 +63,18 @@ def virtual(self, **kwargs): |
33 |
self.qatracker.add_error(myqakey, ebuild.relative_path) |
34 |
return False |
35 |
|
36 |
+ def homepage_urischeme(self, **kwargs): |
37 |
+ ebuild = kwargs.get('ebuild').get() |
38 |
+ if kwargs.get('catdir') != "virtual": |
39 |
+ for homepage in |
40 |
portage.dep.use_reduce(ebuild.metadata["HOMEPAGE"], |
41 |
matchall=True,flat=True): |
42 |
+ if URISCHEME_RE.match(homepage) is None: |
43 |
+ self.qatracker.add_error("HOMEPAGE.missingurischeme", |
44 |
ebuild.relative_path ) |
45 |
+ return False |
46 |
+ |
47 |
@property |
48 |
def runInPkgs(self): |
49 |
return (False, []) |
50 |
|
51 |
@property |
52 |
def runInEbuilds(self): |
53 |
- return (True, [self.invalidchar, self.missing, self.old_virtual, |
54 |
self.virtual]) |
55 |
+ return (True, [self.invalidchar, self.missing, self.old_virtual, |
56 |
self.virtual, self.homepage_urischeme]) |
57 |
diff --git a/repoman/pym/repoman/qa_data.py b/repoman/pym/repoman/qa_data.py |
58 |
index c3f4207..29a95ab 100644 |
59 |
--- a/repoman/pym/repoman/qa_data.py |
60 |
+++ b/repoman/pym/repoman/qa_data.py |
61 |
@@ -115,6 +115,8 @@ |
62 |
"Ebuilds that have a missing or empty HOMEPAGE variable"), |
63 |
"HOMEPAGE.virtual": ( |
64 |
"Virtuals that have a non-empty HOMEPAGE variable"), |
65 |
+ "HOMEPAGE.missingurischeme": ( |
66 |
+ "HOMEPAGE is missing an URI scheme"), |
67 |
"PDEPEND.suspect": ( |
68 |
"PDEPEND contains a package that usually only belongs in DEPEND."), |
69 |
"LICENSE.syntax": ( |
70 |
|
71 |
|
72 |
|
73 |
On Mon, Jan 9, 2017 at 1:04 AM, Zac Medico <zmedico@g.o> wrote: |
74 |
|
75 |
> On 01/07/2017 05:32 AM, Michael Orlitzky wrote: |
76 |
> > On 01/07/2017 06:08 AM, Wim Muskee wrote: |
77 |
> >> |
78 |
> >> URISCHEME_RE = re.compile(r'^[a-z\-]+://') |
79 |
> >> |
80 |
> >> ... |
81 |
> >> |
82 |
> >> URISCHEME_RE.match(ebuild.metadata.get("HOMEPAGE")) is None: |
83 |
> >> |
84 |
> > |
85 |
> > The PMS allows some weird stuff in HOMEPAGE: |
86 |
> > |
87 |
> > https://dev.gentoo.org/~ulm/pms/head/pms.html#x1-760008 |
88 |
> > |
89 |
> > Specifically, |
90 |
> > |
91 |
> > In addition, SRC_URI, HOMEPAGE, RESTRICT, PROPERTIES, LICENSE and |
92 |
> > REQUIRED_USE use dependency-style specifications to specify their |
93 |
> > values. |
94 |
> > |
95 |
> > That means that something like, |
96 |
> > |
97 |
> > HOMEPAGE="branding? ( https://www.mozilla.org/ ) |
98 |
> > !branding? ( https://www.gentoo.org/ )" |
99 |
> > |
100 |
> > would be valid. It's a little crazy, but there it is. |
101 |
> > |
102 |
> > If you can figure out a way to parse a dependency spec (this has to |
103 |
> > exist somewhere in repoman/portage), then you can run your check against |
104 |
> > the URLs at the leaf nodes. At that point, it should be relatively easy |
105 |
> > to update the regex to match the RFC =) |
106 |
> > |
107 |
> > https://tools.ietf.org/html/rfc3986#section-3.1 |
108 |
> |
109 |
> This will return a flat list: |
110 |
> |
111 |
> portage.dep.use_reduce(ebuild.metadata["HOMEPAGE"], matchall=True, |
112 |
> flat=True) |
113 |
> -- |
114 |
> Thanks, |
115 |
> Zac |
116 |
> |
117 |
> |