Skip to content
Merged
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
10 changes: 8 additions & 2 deletions src/license.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ std::vector<std::string> identify_license_text(std::span<const uint8_t> data) {
};

// GNU family — disambiguate Affero/Lesser/Library and version by the dated
// title line. LGPL 2.0 (1991) is titled "Library General Public License";
// title line. LGPL 2.0 (1991) is titled "GNU LIBRARY GENERAL PUBLIC LICENSE";
// the 2.1 (1999) rename to "Lesser" is why v2 needs its own marker (without
// it an LGPL-2.0 COPYING is mis-identified as GPL-2.0).
//
// `library` matches only the all-caps *title*, never the mixed-case phrase
// "GNU Library General Public License": the latter appears in the GPLv2
// *preamble* ("...covered by the GNU Library General Public License
// instead.)"), so matching it flipped a genuine GPL-2.0 file to LGPL-2.0 and
// dropped GPL-2.0 entirely.
bool affero = has("GNU AFFERO GENERAL PUBLIC LICENSE") || has("GNU Affero");
bool lesser = has("GNU LESSER GENERAL PUBLIC LICENSE") || has("Lesser General Public");
bool library = has("GNU LIBRARY GENERAL PUBLIC LICENSE") || has("Library General Public License");
bool library = has("GNU LIBRARY GENERAL PUBLIC LICENSE");
if (has("Version 3, 29 June 2007")) {
if (affero) add("AGPL-3.0");
else if (lesser) add("LGPL-3.0");
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,20 @@ static void test_license() {
// and plain GPL-2.0 is still GPL-2.0 (no false LGPL).
CHECK(lic_text("GNU GENERAL PUBLIC LICENSE\n Version 2, June 1991\n") ==
std::vector<std::string>{"GPL-2.0"});
// Regression: the real GPLv2 *preamble* names the LGPL ("...covered by the
// GNU Library General Public License instead."). That mixed-case mention must
// NOT flip a genuine GPL-2.0 file to LGPL-2.0, nor drop GPL-2.0. Only the
// all-caps LGPL *title* means LGPL-2.0.
auto gpl2_preamble = lic_text(
"GNU GENERAL PUBLIC LICENSE\n Version 2, June 1991\n\n"
" (Some other Free Software Foundation software is covered by the GNU\n"
"Library General Public License instead.) You can apply it too.\n");
CHECK(gpl2_preamble.size() == 1 && gpl2_preamble[0] == "GPL-2.0");
// and a real LGPL-2.0 (caps title) is still LGPL-2.0, even with a preamble.
auto lgpl2_full = lic_text(
"GNU LIBRARY GENERAL PUBLIC LICENSE\n Version 2, June 1991\n\n"
" This library is free software; you can redistribute it ...\n");
CHECK(lgpl2_full.size() == 1 && lgpl2_full[0] == "LGPL-2.0");

// New markers.
CHECK(lic_text("Boost Software License - Version 1.0") == std::vector<std::string>{"BSL-1.0"});
Expand Down
Loading