Skip to content

Commit

Permalink
Fixes Jabref#7305: the RFC fetcher is not compatible with the draftFi…
Browse files Browse the repository at this point in the history
…x for issue 7305 (#7674)
  • Loading branch information
ruanych authored May 3, 2021
1 parent 596323b commit 2db48bd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where urls must be embedded in a style tag when importing EndNote style Xml files. Now it can parse url with or without a style tag. [#6199](https://github.com/JabRef/jabref/issues/6199)
- We fixed an issue where the article title with colon fails to download the arXiv link (pdf file). [#7660](https://github.com/JabRef/issues/7660)
- We fixed an issue where the keybinding for delete entry did not work on the main table [7580](https://github.com/JabRef/jabref/pull/7580)
- We fixed an issue where the RFC fetcher is not compatible with the draft [7305](https://github.com/JabRef/jabref/issues/7305)

### Removed

Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
public class RfcFetcher implements IdBasedParserFetcher {

private final static String DRAFT_PREFIX = "draft";
private final ImportFormatPreferences importFormatPreferences;

public RfcFetcher(ImportFormatPreferences importFormatPreferences) {
Expand All @@ -38,11 +39,21 @@ public Optional<HelpFile> getHelpPage() {
return Optional.of(HelpFile.FETCHER_RFC);
}

/**
* Get the URL of the RFC resource according to the given identifier
*
* @param identifier the ID
* @return the URL of the RFC resource
*/
@Override
public URL getUrlForIdentifier(String identifier) throws URISyntaxException, MalformedURLException, FetcherException {
// Add "rfc" prefix if user's search entry was numerical

String prefixedIdentifier = identifier;
prefixedIdentifier = (!identifier.toLowerCase().startsWith("rfc")) ? "rfc" + prefixedIdentifier : prefixedIdentifier;
// if not a "draft" version
if (!identifier.toLowerCase().startsWith(DRAFT_PREFIX)) {
// Add "rfc" prefix if user's search entry was numerical
prefixedIdentifier = (!identifier.toLowerCase().startsWith("rfc")) ? "rfc" + prefixedIdentifier : prefixedIdentifier;
}

URIBuilder uriBuilder = new URIBuilder("https://datatracker.ietf.org/doc/" + prefixedIdentifier + "/bibtex/");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;
import org.jabref.testutils.category.FetcherTest;
Expand Down Expand Up @@ -47,6 +48,29 @@ public void getNameReturnsEqualIdName() {
assertEquals("RFC", fetcher.getName());
}

@Test
public void performSearchByIdFindsEntryWithDraftIdentifier() throws Exception {
BibEntry bibDraftEntry = new BibEntry();
bibDraftEntry.setType(StandardEntryType.TechReport);
bibDraftEntry.setField(InternalField.KEY_FIELD, "fielding-http-spec-01");
bibDraftEntry.setField(StandardField.AUTHOR, "Henrik Nielsen and Roy T. Fielding and Tim Berners-Lee");
bibDraftEntry.setField(StandardField.DAY, "20");
bibDraftEntry.setField(StandardField.INSTITUTION, "Internet Engineering Task Force");
bibDraftEntry.setField(StandardField.MONTH, "#dec#");
bibDraftEntry.setField(StandardField.NOTE, "Work in Progress");
bibDraftEntry.setField(StandardField.NUMBER, "draft-fielding-http-spec-01");
bibDraftEntry.setField(StandardField.PAGETOTAL, "41");
bibDraftEntry.setField(StandardField.PUBLISHER, "Internet Engineering Task Force");
bibDraftEntry.setField(StandardField.TITLE, "{Hypertext Transfer Protocol -- HTTP/1.0}");
bibDraftEntry.setField(StandardField.TYPE, "Internet-Draft");
bibDraftEntry.setField(StandardField.URL, "https://datatracker.ietf.org/doc/html/draft-fielding-http-spec-01");
bibDraftEntry.setField(StandardField.YEAR, "1994");
bibDraftEntry.setField(StandardField.ABSTRACT, "The Hypertext Transfer Protocol (HTTP) is an application-level protocol with the lightness and speed necessary for distributed, collaborative, hypermedia information systems. It is a generic, stateless, object-oriented protocol which can be used for many tasks, such as name servers and distributed object management systems, through extension of its request methods (commands). A feature of HTTP is the typing and negotiation of data representation, allowing systems to be built independently of the data being transferred. HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification reflects preferred usage of the protocol referred to as 'HTTP/1.0', and is compatible with the most commonly used HTTP server and client programs implemented prior to November 1994.");
bibDraftEntry.setCommentsBeforeEntry("%% You should probably cite draft-ietf-http-v10-spec instead of this I-D.");

assertEquals(Optional.of(bibDraftEntry), fetcher.performSearchById("draft-fielding-http-spec"));
}

@Test
public void performSearchByIdFindsEntryWithRfcPrefix() throws Exception {
assertEquals(Optional.of(bibEntry), fetcher.performSearchById("RFC1945"));
Expand All @@ -62,6 +86,11 @@ public void performSearchByIdFindsNothingWithoutIdentifier() throws Exception {
assertEquals(Optional.empty(), fetcher.performSearchById(""));
}

@Test
public void performSearchByIdFindsNothingWithValidDraftIdentifier() throws Exception {
assertEquals(Optional.empty(), fetcher.performSearchById("draft-test-draft-spec"));
}

@Test
public void performSearchByIdFindsNothingWithValidIdentifier() throws Exception {
assertEquals(Optional.empty(), fetcher.performSearchById("RFC9999"));
Expand Down

0 comments on commit 2db48bd

Please sign in to comment.