Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize to "copyright" and "trademark" rather than single-char variants #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions licensedb/internal/normalize/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ var (
)

// 9.1.1 "©", "(c)", or "Copyright" should be considered equivalent and interchangeable.
copyrightRe = regexp.MustCompile("copyright|\\(c\\)")
trademarkRe = regexp.MustCompile("trademark(s?)|\\(tm\\)")
copyrightRe = regexp.MustCompile("©|\\(c\\)")
trademarkRe = regexp.MustCompile("trademarks|\\(tm\\)|™")

// extra cleanup
brokenLinkRe = regexp.MustCompile("http s ://")
urlCleanupRe = regexp.MustCompile("[<(](http(s?)://[^\\s]+)[)>]")
copyrightLineRe = regexp.MustCompile("(?m)^((©.*)|(all rights reserved(\\.)?)|(li[cs]en[cs]e))\n")
copyrightLineRe = regexp.MustCompile("(?m)^((copyright.*)|(all rights reserved(\\.)?)|(li[cs]en[cs]e))\n")
nonAlphaNumRe = regexp.MustCompile("[^- \\na-z0-9]")

// used in Split()
Expand Down Expand Up @@ -128,8 +128,8 @@ func LicenseText(text string, strictness Strictness) string {
text = wordReplacer.Replace(text)

// 9. Copyright Symbol
text = copyrightRe.ReplaceAllString(text, "©")
text = trademarkRe.ReplaceAllString(text, "")
text = copyrightRe.ReplaceAllString(text, "copyright")
text = trademarkRe.ReplaceAllString(text, "trademark")

// fix broken URLs in SPDX source texts
text = brokenLinkRe.ReplaceAllString(text, "https://")
Expand All @@ -155,7 +155,9 @@ func LicenseText(text string, strictness Strictness) string {
// there are common mismatches because of trailing dots
text = strings.Replace(text, ".", "", -1)
// usually copyright lines are custom and occur multiple times
text = strings.Replace(text, "copyright notice", "PLACEHOLDER", -1)
text = copyrightLineRe.ReplaceAllString(text, "")
text = strings.Replace(text, "PLACEHOLDER", "copyright notice", -1)
}

if strictness > Moderate {
Expand Down
1 change: 1 addition & 0 deletions licensedb/internal/normalize/normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ permissions granted by this license.`},
{"punctuation", "a-‒–—―⁓⸺⸻~˗‐‑⁃⁻₋−∼⎯⏤─➖𐆑֊﹘﹣-", "a-"},
{"bullet", "-\n*\n✱\n﹡\n•\n●\n⚫\n⏺\n🞄\n∙\n⋅\n", ""},
{"license", "", ""},
{"copyright notice", "copyright notice", "copyright notice"},
}

for _, tc := range tt {
Expand Down