Skip to content

Commit

Permalink
Fix invalid filename with curly braces and fix wrong encoding in pars…
Browse files Browse the repository at this point in the history
…er (#5926)

* debug version

* use utf8 in getBytes to read correct bytes

* Fixes filenames by not allowing curly braces

* disable debug mode
  • Loading branch information
Siedlerchr committed Feb 12, 2020
1 parent 259bca0 commit 567dc68
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

- We cleaned up the group add/edit dialog. [#5826](https://github.com/JabRef/jabref/pull/5826)
- We reintroduced the index column. [#5844](https://github.com/JabRef/jabref/pull/5844)
- Filenames of external files can no longer contain curly braces


### Fixed

Expand All @@ -30,6 +32,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where cleaning up entries broke web URLs, if "Make paths of linked files relative (if possible)" was enabled, which resulted in various other issues subsequently. [#5861](https://github.com/JabRef/jabref/issues/5861)
- We fixed an issue where the tab "Required fields" of the entry editor did not show all required fields, if at least two of the defined required fields are linked with a logical or. [#5859](https://github.com/JabRef/jabref/issues/5859)
- We fixed several issues concerning managing external file types: Now everything is usable and fully functional. Previously, there were problems with the radio buttons, with saving the settings and with loading an input field value. Furthermore, different behavior for Windows and other operating systems was given, which was unified as well. [#5846](https://github.com/JabRef/jabref/issues/5846)
- We fixed an issue where entries containing Unicode charaters were not parsed correctly [#5899](https://github.com/JabRef/jabref/issues/5899)
- We fixed an issue where an entry containing an external filename with curly braces could not be saved. Curly braces are now longer allowed in filenames. [#5899](https://github.com/JabRef/jabref/issues/5899)
- We fixed an issue where changing the type of an entry did not update the main table [#5906](https://github.com/JabRef/jabref/issues/5906)


Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/logic/importer/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

import org.jabref.model.entry.BibEntry;

/**
* A parser converts an {@link InputStream} into a list of {@link BibEntry}.
/** * A parser converts an {@link InputStream} into a list of {@link BibEntry}.
*/
public interface Parser {

List<BibEntry> parseEntries(InputStream inputStream) throws ParseException;

default List<BibEntry> parseEntries(String dataString) throws ParseException {
return parseEntries(new ByteArrayInputStream(dataString.getBytes()));
return parseEntries(new ByteArrayInputStream(dataString.getBytes(StandardCharsets.UTF_8)));
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/util/io/FileNameCleaner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* This class is based on http://stackoverflow.com/a/5626340/873282
*
* extended with LEFT CURLY BRACE and RIGHT CURLY BRACE
* Replaces illegal characters in given file paths.
*/
public class FileNameCleaner {
Expand All @@ -21,7 +21,7 @@ public class FileNameCleaner {
42,
58,
60, 62, 63,
124
123, 124, 125
};
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public void testCleanDirectoryNameForWindows() {
assertEquals("subdir\\legalFilename.txt", FileNameCleaner.cleanDirectoryName("subdir\\legalFilename.txt"));
assertEquals("illegalFilename\\_____.txt", FileNameCleaner.cleanDirectoryName("illegalFilename\\?*<>|.txt"));
}

@Test
public void testCleanCurlyBracesAsWell() {
assertEquals("The Evolution of Sentiment_ Analysis_A Review of Research Topics, Venues, and Top Cited Papers.PDF", FileNameCleaner.cleanFileName("The Evolution of Sentiment} Analysis}A Review of Research Topics, Venues, and Top Cited Papers.PDF"));
}
}

0 comments on commit 567dc68

Please sign in to comment.