File tree Expand file tree Collapse file tree
plugins/package-managers/node/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -186,10 +186,20 @@ private object AuthorListSerializer : JsonTransformingSerializer<List<Author>>(s
186186 is JsonObject -> listOf (this )
187187
188188 is JsonPrimitive -> {
189- parseAuthorString(contentOrNull)
190- .filter { it.name != null }
191- .map { Author (checkNotNull(it.name), it.email, it.homepage) }
192- .map { JSON .encodeToJsonElement(it) }
189+ parseAuthorString(contentOrNull).mapNotNull { info ->
190+ when {
191+ info.name != null -> Author (checkNotNull(info.name), info.email, info.homepage)
192+ info.email == null -> null
193+ else -> {
194+ val nameFromEmail = checkNotNull(info.email).substringBefore(' @' )
195+ .replace(' .' , ' ' )
196+ .replace(Regex (" \\ b([a-z])" )) { it.value.uppercase() }
197+ Author (nameFromEmail, info.email, info.homepage)
198+ }
199+ }
200+ }.map {
201+ JSON .encodeToJsonElement(it)
202+ }
193203 }
194204
195205 else -> throw SerializationException (" Unexpected JSON element." )
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson.Author
2929
3030class PackageJsonTest : WordSpec ({
3131 " parsePackageJson()" should {
32- " deserialize the author from a textual node" {
32+ " deserialize the author from a primitive node with name and email " {
3333 val json = """
3434 {
3535 "author": "Jane Doe <jane.doe@example.com>"
@@ -43,6 +43,20 @@ class PackageJsonTest : WordSpec({
4343 )
4444 }
4545
46+ " deserialize the author from a primitive node with email only" {
47+ val json = """
48+ {
49+ "author": "<jane.doe@example.com>"
50+ }
51+ """ .trimIndent()
52+
53+ val packageJson = parsePackageJson(json)
54+
55+ packageJson.authors should containExactlyInAnyOrder(
56+ Author (name = "Jane Doe ", email = "jane.doe@example.com")
57+ )
58+ }
59+
4660 " deserialize the author from an object node" {
4761 val json = """
4862 {
You can’t perform that action at this time.
0 commit comments