Skip to content

Commit 2b55ddb

Browse files
authored
Use stricter regex (JabRef#11720)
1 parent 4b633aa commit 2b55ddb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/org/jabref/logic/openoffice/ReferenceMark.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ReferenceMark {
1515

1616
private static final Logger LOGGER = LoggerFactory.getLogger(ReferenceMark.class);
1717

18-
private static final Pattern REFERENCE_MARK_FORMAT = Pattern.compile("^((?:JABREF_\\w+ CID_\\w+(?:,\\s*)?)+)(\\s*\\w+)?$");
18+
private static final Pattern REFERENCE_MARK_FORMAT = Pattern.compile("^(JABREF_\\w+ CID_\\d+(?:, JABREF_\\w+ CID_\\d+)*) (\\w+)$");
1919
private static final Pattern ENTRY_PATTERN = Pattern.compile("JABREF_(\\w+) CID_(\\w+)");
2020

2121
private final String name;
@@ -24,7 +24,11 @@ public class ReferenceMark {
2424
private String uniqueId;
2525

2626
/**
27-
* @param name Format: <code>JABREF_{citationKey} CID_{citationNumber} {uniqueId}</code>
27+
* @param name Allowed formats:
28+
* Single entry: <code>JABREF_{citationKey} CID_{citationNumber} {uniqueId}</code>
29+
* Group of entries: <code>JABREF_{citationKey1} CID_{citationNumber1}, JABREF_{citationKey2} CID_{citationNumber2}, ..., JABREF_{citationKeyN} CID_{citationNumberN} {uniqueId}</code>
30+
* Disallowed: <code>JABREF_{citationKey} CID_{citationNumber}</code> (no unique ID at the end)
31+
* Disallowed: <code>JABREF_{citationKey1} CID_{citationNumber1} JABREF_{citationKey2} CID_{citationNumber2} {uniqueId}</code> (no comma between entries)
2832
*/
2933
public ReferenceMark(String name) {
3034
this.name = name;

0 commit comments

Comments
 (0)