Skip to content

Commit

Permalink
Use RemoveLatexCommandsFormatter directly
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Nov 9, 2019
1 parent 5f7fe7e commit cbb3836
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import java.util.Optional;

import org.jabref.logic.cleanup.DoiCleanup;
import org.jabref.logic.formatter.bibtexfields.CleanupUrlFormatter;
import org.jabref.logic.formatter.bibtexfields.ClearFormatter;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.SearchBasedParserFetcher;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.layout.format.RemoveLatexCommandsFormatter;
import org.jabref.model.cleanup.FieldFormatterCleanup;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.InternalField;
Expand Down Expand Up @@ -64,8 +64,10 @@ public void doPostCleanup(BibEntry entry) {
FieldFormatterCleanup clearTimestampFormatter = new FieldFormatterCleanup(InternalField.TIMESTAMP, new ClearFormatter());
clearTimestampFormatter.cleanup(entry);

FieldFormatterCleanup cleanUpUrlFormatter = new FieldFormatterCleanup(StandardField.URL, new CleanupUrlFormatter());
cleanUpUrlFormatter.cleanup(entry);
// unescape the the contents of the URL field
entry.getField(StandardField.URL)
.map(url -> new RemoveLatexCommandsFormatter().format(url))
.ifPresent(url -> entry.setField(StandardField.URL, url));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ void latexCommandsRemoved() {
assertEquals("http://pi.informatik.uni-siegen.de/stt/36_2/./03_Technische_Beitraege/ZEUS2016/beitrag_2.pdf", formatter.format("http://pi.informatik.uni-siegen.de/stt/36\\_2/./03\\_Technische\\_Beitraege/ZEUS2016/beitrag\\_2.pdf"));
}

@Test
void urlencodedSlashesAreAlsoConverted() {
// the caller has to pay attention that this does not happen
assertEquals("jabref.org/test/test", formatter.format("jabref.org/test%2Ftest"));
}

@Test
void formatExample() {
assertEquals("http://www.focus.de/" +
Expand Down

0 comments on commit cbb3836

Please sign in to comment.