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

Trailing comma in author name causes error #10776

Merged
merged 4 commits into from
Sep 30, 2024
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
5 changes: 5 additions & 0 deletions doc/release-notes/10343-trailing-comma.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Trailing commas in author name now permitted

When an author name ends on a comma (e.g. "Smith,") a dataset cannot be properly loaded when using json-ld. A null check fixes this.

For more information, see #10343.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static JsonObject getPersonOrOrganization(String name, boolean organizati
if (!name.replaceFirst(",", "").contains(",")) {
// contributorName=<FamilyName>, <FirstName>
String[] fullName = name.split(", ");
givenName = fullName[1];
givenName = fullName.length > 1 ? fullName[1] : null;
familyName = fullName[0];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public void testName() {
verifyIsPerson("kcjim11, kcjim11", "kcjim11", "kcjim11");

verifyIsPerson("Bartholomew 3, James", "James", "Bartholomew 3");
verifyIsPerson("Smith, ", null, "Smith");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is no space at the end? Should you add that as another test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifying failed because the compared JsonObject was normalized via an util method. I added the normalization to the comparison in the assertion and added the other test case.

verifyIsPerson("Smith,", null, "Smith");
}

private void verifyIsOrganization(String fullName) {
Expand All @@ -106,7 +108,7 @@ private void verifyIsPerson(String fullName, String givenName, String familyName
private void verifyIsPerson(String fullName, String givenName, String familyName, boolean isPerson) {
JsonObject obj = PersonOrOrgUtil.getPersonOrOrganization(fullName, false, isPerson);
System.out.println(JsonUtil.prettyPrint(obj));
assertEquals(obj.getString("fullName"),fullName);
assertEquals(obj.getString("fullName"), StringUtil.normalize(fullName));
assertTrue(obj.getBoolean("isPerson"));
assertEquals(obj.containsKey("givenName"), givenName != null);
if(obj.containsKey("givenName") && givenName != null) {
Expand Down
Loading