From 2db48bda09857f753dd4fd376ee6564ebfd5860a Mon Sep 17 00:00:00 2001 From: Ruan <47767371+Ryyyc@users.noreply.github.com> Date: Mon, 3 May 2021 13:26:28 -0700 Subject: [PATCH] Fixes Jabref#7305: the RFC fetcher is not compatible with the draftFix for issue 7305 (#7674) --- CHANGELOG.md | 1 + .../logic/importer/fetcher/RfcFetcher.java | 15 ++++++++-- .../importer/fetcher/RfcFetcherTest.java | 29 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b832e4b2da..15ff79e8072 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java index b1108a82744..ca38ebe0d17 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/RfcFetcher.java @@ -22,6 +22,7 @@ */ public class RfcFetcher implements IdBasedParserFetcher { + private final static String DRAFT_PREFIX = "draft"; private final ImportFormatPreferences importFormatPreferences; public RfcFetcher(ImportFormatPreferences importFormatPreferences) { @@ -38,11 +39,21 @@ public Optional 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/"); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java index 42f52d0985b..4a6bb057a51 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java @@ -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; @@ -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")); @@ -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"));