Skip to content

Commit a959b49

Browse files
committed
Ensue rule id is unique also for rule without texts
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent e8c0df6 commit a959b49

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/licensedcode/models.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,14 +2000,12 @@ def _from_expression(cls, license_expression=None, identifier=None, **kwargs):
20002000

20012001
def compute_unique_id(self):
20022002
"""
2003-
Return a a unique id string based on this rule content. (Today this is
2004-
an SHA1 checksum of the text, but that's an implementation detail)
2003+
Return a a unique id string based on this rule content.
2004+
(Today this is an SHA1 checksum of the identifierm expression and text,
2005+
but this is an implementation detail)
20052006
"""
2006-
if not self.text:
2007-
text = "None"
2008-
else:
2009-
text = self.text
2010-
return sha1(text.encode('utf-8')).hexdigest()
2007+
content = f'{self.identifier!r}{self.license_expression!r}{self.text!r}'
2008+
return sha1(content.encode('utf-8')).hexdigest()
20112009

20122010
def load_data(self, rule_file):
20132011
"""

0 commit comments

Comments
 (0)