Skip to content

Commit 537b82d

Browse files
committed
Link is the only mandatory field #98
1 parent 8db91af commit 537b82d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/main/java/net/sf/jabref/model/entry/FileField.java

+6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ private static FileField.ParsedFileField convert(List<String> entry) {
168168
entry.add("");
169169
}
170170
FileField.ParsedFileField field = new FileField.ParsedFileField(entry.get(0), entry.get(1), entry.get(2));
171+
// link is only mandatory field
172+
if(field.description.isEmpty() && field.link.isEmpty() && !field.fileType.isEmpty()) {
173+
field = new ParsedFileField("", field.fileType, "");
174+
} else if(!field.description.isEmpty() && field.link.isEmpty() && field.fileType.isEmpty()) {
175+
field = new ParsedFileField("", field.description, "");
176+
}
171177
entry.clear();
172178
return field;
173179
}

src/test/java/net/sf/jabref/model/entry/FileFieldTest.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.junit.Test;
44

5+
import java.util.Arrays;
56
import java.util.Collections;
67

78
import static org.junit.Assert.*;
@@ -31,6 +32,15 @@ public void ingoreMissingDescription() throws Exception {
3132
assertEquals(Collections.singletonList(new FileField.ParsedFileField("", "wei2005ahp.pdf", "PDF")), FileField.parse(input));
3233
}
3334

35+
@Test
36+
public void interpreteLinkAsOnlyMandatoryField() throws Exception {
37+
String single = "wei2005ahp.pdf";
38+
String multiple = "wei2005ahp.pdf;other.pdf";
39+
40+
assertEquals(Collections.singletonList(new FileField.ParsedFileField("", "wei2005ahp.pdf", "")), FileField.parse(single));
41+
assertEquals(Arrays.asList(new FileField.ParsedFileField("", "wei2005ahp.pdf", ""), new FileField.ParsedFileField("", "other.pdf", "")), FileField.parse(multiple));
42+
}
43+
3444
@Test
3545
public void escapedCharactersInDescription() throws Exception {
3646
String input = "test\\:\\;:wei2005ahp.pdf:PDF";
@@ -53,10 +63,14 @@ public void handleEscapedFilePath() throws Exception {
5363
}
5464

5565
@Test
56-
public void tooLessSeparators() throws Exception {
57-
String input = "desc:";
58-
59-
assertEquals(Collections.singletonList(new FileField.ParsedFileField("desc", "", "")), FileField.parse(input));
66+
public void subsetOfFieldsResultsInFileLink() throws Exception {
67+
String descOnly = "file.pdf::";
68+
String fileOnly = ":file.pdf";
69+
String typeOnly = "::file.pdf";
70+
71+
assertEquals(Collections.singletonList(new FileField.ParsedFileField("", "file.pdf", "")), FileField.parse(descOnly));
72+
assertEquals(Collections.singletonList(new FileField.ParsedFileField("", "file.pdf", "")), FileField.parse(fileOnly));
73+
assertEquals(Collections.singletonList(new FileField.ParsedFileField("", "file.pdf", "")), FileField.parse(typeOnly));
6074
}
6175

6276
@Test

0 commit comments

Comments
 (0)