Skip to content

Commit 6759c63

Browse files
committed
Fix #233: Do not trim MarcXML record leader
Changes `MarcXmlHandler` to no longer trim the record leader.
1 parent 03a2220 commit 6759c63

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/org/culturegraph/mf/stream/converter/xml/MarcXmlHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void endElement(final String uri, final String localName, final String qN
7979
getReceiver().endRecord();
8080

8181
}else if(LEADER.equals(localName)){
82-
getReceiver().literal(currentTag, builder.toString().trim());
82+
getReceiver().literal(currentTag, builder.toString());
8383

8484
}
8585
}

src/test/java/org/culturegraph/mf/stream/converter/xml/MarcXmlHandlerTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
public final class MarcXmlHandlerTest {
3434

35+
private static final String LEADER = "leader";
3536
private static final String CONTROLFIELD = "controlfield";
3637
private static final String NAMESPACE = "http://www.loc.gov/MARC21/slim";
3738

@@ -67,5 +68,18 @@ public void shouldFindTagAttributeAtSecondPositionInControlFieldElement()
6768

6869
verify(receiver).literal("001", fieldValue);
6970
}
71+
72+
@Test
73+
public void issue233ShouldNotRemoveWhitespaceFromLeader()
74+
throws SAXException {
75+
final AttributesImpl attributes = new AttributesImpl();
76+
final String leaderValue = " cdefghijklmnopqrstuv ";
77+
78+
marcXmlHandler.startElement(NAMESPACE, LEADER, "", attributes);
79+
marcXmlHandler.characters(leaderValue.toCharArray(), 0, leaderValue.length());
80+
marcXmlHandler.endElement(NAMESPACE, LEADER, "");
81+
82+
verify(receiver).literal("leader", leaderValue);
83+
}
7084

7185
}

0 commit comments

Comments
 (0)