Skip to content

Commit

Permalink
Use stricter regex (JabRef#11720)
Browse files Browse the repository at this point in the history
  • Loading branch information
subhramit authored Sep 7, 2024
1 parent 4b633aa commit 2b55ddb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/logic/openoffice/ReferenceMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ReferenceMark {

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

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

private final String name;
Expand All @@ -24,7 +24,11 @@ public class ReferenceMark {
private String uniqueId;

/**
* @param name Format: <code>JABREF_{citationKey} CID_{citationNumber} {uniqueId}</code>
* @param name Allowed formats:
* Single entry: <code>JABREF_{citationKey} CID_{citationNumber} {uniqueId}</code>
* Group of entries: <code>JABREF_{citationKey1} CID_{citationNumber1}, JABREF_{citationKey2} CID_{citationNumber2}, ..., JABREF_{citationKeyN} CID_{citationNumberN} {uniqueId}</code>
* Disallowed: <code>JABREF_{citationKey} CID_{citationNumber}</code> (no unique ID at the end)
* Disallowed: <code>JABREF_{citationKey1} CID_{citationNumber1} JABREF_{citationKey2} CID_{citationNumber2} {uniqueId}</code> (no comma between entries)
*/
public ReferenceMark(String name) {
this.name = name;
Expand Down

0 comments on commit 2b55ddb

Please sign in to comment.