diff --git a/src/cluecode/copyrights.py b/src/cluecode/copyrights.py index 29876084168..e3f1b3c2e33 100644 --- a/src/cluecode/copyrights.py +++ b/src/cluecode/copyrights.py @@ -431,6 +431,22 @@ def get_tokens(numbered_lines, splitter=re.compile(r'[\t =;]+').split): # space before in some cases: exclude (digit , (s , (c , (- # this allows to recover from words like KISA(Korean line = re.sub(pattern=r'(\([^rsc\-\d])', repl=r' \g<1>', string=line) + + # Split compact author prefixes such as Author:Frankie.Chu while + # preserving colons elsewhere, for example in URLs. + line = re.sub( + pattern=r'(^|\s)([Aa]uthor):(?=\S)', + repl=r'\1\2 ', + string=line, + ) + + # Normalize dotted names only when they follow an Author tag. + line = re.sub( + pattern=r'(^|\s)([Aa]uthor)\s+([A-Z][a-z]+)\.([A-Z][a-z]+)(?=\b|[,;])', + repl=r'\1\2 \3 \4', + string=line, + ) + for tok in splitter(line): # strip trailing quotes+comma if tok.endswith("',"): diff --git a/tests/cluecode/test_copyrights_basic.py b/tests/cluecode/test_copyrights_basic.py index 1fbafcf5488..b6f6790d5da 100644 --- a/tests/cluecode/test_copyrights_basic.py +++ b/tests/cluecode/test_copyrights_basic.py @@ -319,6 +319,22 @@ def test_detect_with_lines_only_holders(self): )) assert results == expected + def test_detect_author_without_space_and_with_dotted_name(self): + numbered_lines = [ + (1, '// Date:9 April,2012'), + (2, '// Author:Frankie.Chu'), + ] + expected = [ + copyrights.AuthorDetection('Frankie Chu', 2, 2), + ] + results = list(copyrights.detect_copyrights_from_lines( + numbered_lines, + include_copyrights=False, + include_holders=False, + include_authors=True, + )) + assert results == expected + def check_full_detections(expected, test_file): """