Skip to content

Commit

Permalink
QuotedStringTokenizer now does not unquote (#4830)
Browse files Browse the repository at this point in the history
* QuotedStringTokenizer now does not unquote

* Unquote to fix test failures

* Add javadoc to nextToken
  • Loading branch information
abepolk authored and Siedlerchr committed Apr 5, 2019
1 parent 7f7d81a commit 17bfe91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/logic/importer/util/GroupsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ private static AbstractGroup automaticKeywordGroupFromString(String string) {
String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken()));
String field = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
Character delimiter = tok.nextToken().charAt(0);
Character hierarchicalDelimiter = tok.nextToken().charAt(0);
Character delimiter = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR).charAt(0);
Character hierarchicalDelimiter = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR).charAt(0);
AutomaticKeywordGroup newGroup = new AutomaticKeywordGroup(name, context, field, delimiter, hierarchicalDelimiter);
addGroupDetails(tok, newGroup);
return newGroup;
Expand Down Expand Up @@ -212,7 +212,7 @@ private static ExplicitGroup explicitGroupFromString(String input, Character key
QuotedStringTokenizer tok = new QuotedStringTokenizer(input.substring(MetadataSerializationConfiguration.EXPLICIT_GROUP_ID.length()),
MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);

String name = tok.nextToken();
String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
try {
int context = Integer.parseInt(tok.nextToken());
ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumberOrDefault(context), keywordSeparator);
Expand All @@ -230,7 +230,7 @@ private static ExplicitGroup legacyExplicitGroupFromString(String input, Charact
QuotedStringTokenizer tok = new QuotedStringTokenizer(input.substring(MetadataSerializationConfiguration.LEGACY_EXPLICIT_GROUP_ID.length()),
MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);

String name = tok.nextToken();
String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
try {
int context = Integer.parseInt(tok.nextToken());
ExplicitGroup newGroup = new ExplicitGroup(name, GroupHierarchyType.getByNumberOrDefault(context), keywordSeparator);
Expand Down Expand Up @@ -274,15 +274,15 @@ private static AbstractGroup searchGroupFromString(String s) {
QuotedStringTokenizer tok = new QuotedStringTokenizer(s.substring(MetadataSerializationConfiguration.SEARCH_GROUP_ID.length()),
MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);

String name = tok.nextToken();
String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
int context = Integer.parseInt(tok.nextToken());
String expression = tok.nextToken();
String expression = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
boolean caseSensitive = Integer.parseInt(tok.nextToken()) == 1;
boolean regExp = Integer.parseInt(tok.nextToken()) == 1;
// version 0 contained 4 additional booleans to specify search
// fields; these are ignored now, all fields are always searched
return new SearchGroup(StringUtil.unquote(name, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR),
GroupHierarchyType.getByNumberOrDefault(context), StringUtil.unquote(expression, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR), caseSensitive, regExp
return new SearchGroup(name,
GroupHierarchyType.getByNumberOrDefault(context), expression, caseSensitive, regExp
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ public QuotedStringTokenizer(String content, String delimiters, char quoteCharac
}
}

/**
* @return the next token from the content string, ending at the next
* unquoted delimiter. Does not unquote the string itself.
*/
public String nextToken() {
char c;
StringBuilder stringBuilder = new StringBuilder();
while (index < contentLength) {
c = content.charAt(index);
if (c == quoteChar) { // next is quoted
++index;
stringBuilder.append(c);
if (index < contentLength) {
stringBuilder.append(content.charAt(index));
// ignore for delimiter search!
Expand Down

0 comments on commit 17bfe91

Please sign in to comment.