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

Support two argument form of \abx@aux@cite macro in DefaultAuxParser #8549

Merged
merged 3 commits into from
Mar 7, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where "Copy DOI url" in the right-click menu of the Entry List would just copy the DOI and not the DOI url. [#8389](https://github.com/JabRef/jabref/issues/8389)
- We fixed an issue where opening the console from the drop-down menu would cause an exception. [#8466](https://github.com/JabRef/jabref/issues/8466)
- We fixed an issue where pasting a URL was replacing + signs by spaces making the URL unreachable. [#8448](https://github.com/JabRef/jabref/issues/8448)
- We fixed an issue where creating subsidiary files from aux files created with some versions of biblatex would produce incorrect results. [#8513](https://github.com/JabRef/jabref/issues/8513)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
public class DefaultAuxParser implements AuxParser {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAuxParser.class);

private static final Pattern CITE_PATTERN = Pattern.compile("\\\\(citation|abx@aux@cite)\\{(.+)\\}");
private static final Pattern CITE_PATTERN = Pattern.compile("\\\\(citation|abx@aux@cite)(\\{\\d+\\})?\\{(?<citationkey>.+)\\}");
private static final Pattern INPUT_PATTERN = Pattern.compile("\\\\@input\\{(.+)\\}");

private final BibDatabase masterDatabase;
Expand Down Expand Up @@ -108,7 +108,7 @@ private void matchCitation(AuxParserResult result, String line) {
Matcher citeMatch = CITE_PATTERN.matcher(line);

while (citeMatch.find()) {
String keyString = citeMatch.group(2);
String keyString = citeMatch.group("citationkey");
String[] keys = keyString.split(",");

for (String key : keys) {
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/jabref/logic/auxparser/AuxParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ void testNormal() throws URISyntaxException, IOException {
}
}

@Test
void testTwoArgMacro() throws URISyntaxException, IOException {
// Result should be identical to that of testNormal

InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Path auxFile = Path.of(AuxParserTest.class.getResource("papertwoargmacro.aux").toURI());
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()).parse(originalReader);

AuxParser auxParser = new DefaultAuxParser(result.getDatabase());
AuxParserResult auxResult = auxParser.parse(auxFile);

assertTrue(auxResult.getGeneratedBibDatabase().hasEntries());
assertEquals(0, auxResult.getUnresolvedKeysCount());
BibDatabase newDB = auxResult.getGeneratedBibDatabase();
List<BibEntry> newEntries = newDB.getEntries();
assertEquals(2, newEntries.size());
assertTrue(newEntries.get(0).hasChanged());
assertTrue(newEntries.get(1).hasChanged());
assertEquals(2, auxResult.getResolvedKeysCount());
assertEquals(2, auxResult.getFoundKeysInAux());
assertEquals(auxResult.getFoundKeysInAux() + auxResult.getCrossRefEntriesCount(),
auxResult.getResolvedKeysCount() + auxResult.getUnresolvedKeysCount());
assertEquals(0, auxResult.getCrossRefEntriesCount());
}
}

@Test
void testNotAllFound() throws URISyntaxException, IOException {
InputStream originalStream = AuxParserTest.class.getResourceAsStream("origin.bib");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
\relax
\abx@aux@cite{0}{Darwin1888}
\abx@aux@cite{0}{Einstein1920}
\bibstyle{plain}
\bibdata{origin}
\bibcite{Darwin1888}{1}
\bibcite{Einstein1920}{2}
\@writefile{toc}{\contentsline {section}{\numberline {1}}{1}}