Skip to content

Implement escaping of keyword delimiters#14637

Merged
calixtus merged 15 commits into
JabRef:mainfrom
BOgdAnSAM-sudo:fix-for-issue-12810
Dec 22, 2025
Merged

Implement escaping of keyword delimiters#14637
calixtus merged 15 commits into
JabRef:mainfrom
BOgdAnSAM-sudo:fix-for-issue-12810

Conversation

@BOgdAnSAM-sudo

@BOgdAnSAM-sudo BOgdAnSAM-sudo commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

Closes #12810

Implemented escaping of delimeters in keywords in KeywordList#parse using (#12888 (comment)) and reworked KeywordList#serialize to match new logic. Also added tests for new functionality

Steps to test

  1. Start JabRef
  2. Create new empty library
  3. Click on "Add example entry"
  4. In example entry locate tab "General"
  5. In Keywords field enter paste following keywords: "Keyword > Keyword", "Keyword > Keyword", "KeywordOne,KeywordTwo", "KeywordOne,KeywordTwo", "keyword\", "keyword".
  6. Keywords field should show: "Keyword > Keyword" and "Keyword > Keyword" as two separate keywords, "KeywordOne,KeywordTwo" as single keyword, "KeywordOne" and "KeywordTwo" as two separate keywords, "KeywordOne", "KeywordOne".
  7. Locate tab "BibTeX sorce"
  8. Tab "BibTeX sorce" should contain line keywords = {Keyword \> Keyword,Keyword > Keyword,KeywordOne\,KeywordTwo, KeywordOne,KeywordTwo,keyword\\,keyword}

After executing this steps we can see that in Keywords field keywords are formatted in readable, 'nice' strings and in "BibTeX sorce" keywords have good unique serialization.

Important note:
When I was testing the GUI, I noticed that it isn't possible to enter a keyword with an escaped delimiter by hand, only paste the whole keyword.

This happens due to logic in org/jabref/gui/fieldeditors/KeywordsEditor; it checks every symbol that is typed into the field, and if this symbol is a delimiter, it automatically commits the new keyword.

I don't know if I should change the logic of KeywordsEditor because it exceeds the scope of this Issue.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • [/] I added screenshots in the PR description (if change is visible to the user)
  • I described the change in CHANGELOG.md in a way that is understandable for the average user (if change is visible to the user)
  • [/] I checked the user documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request updating file(s) in https://github.com/JabRef/user-documentation/tree/main/en.

@github-actions github-actions Bot added good second issue Issues that involve a tour of two or three interweaved components in JabRef status: changes-required Pull requests that are not yet complete labels Dec 17, 2025
@github-actions github-actions Bot removed the status: changes-required Pull requests that are not yet complete label Dec 17, 2025
Comment thread CHANGELOG.md Outdated
Comment thread jablib/src/main/java/org/jabref/model/entry/KeywordList.java Outdated
koppor
koppor previously requested changes Dec 18, 2025
Comment thread jablib/src/test/java/org/jabref/model/entry/KeywordListTest.java
Comment thread jablib/src/test/java/org/jabref/model/entry/KeywordListTest.java Outdated
@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Dec 18, 2025
Comment on lines +159 to +177
@ParameterizedTest
@MethodSource("parseKeywordWithEscapedDelimiterDoesNotSplitKeyword")
void afterFirstParsingNoChangesShouldBeDoneToKeywords(String input, KeywordList expected) {
char delimiter = ',';
KeywordList firstParse = KeywordList.parse(input, delimiter);
String serialized = KeywordList.serialize(firstParse.stream().toList(), delimiter);
KeywordList secondParse = KeywordList.parse(serialized, delimiter);
assertEquals(expected, secondParse);
}

@ParameterizedTest
@MethodSource("serializeKeywordWithNonEscapedDelimiterJoinsKeywordsCorrectly")
void afterFirstSerializeNoChangesShouldBeDoneToKeywords(List<Keyword> input, String expected) {
char delimiter = ',';
String firstSerialize = KeywordList.serialize(input, delimiter);
KeywordList parsed = KeywordList.parse(firstSerialize, delimiter);
String secondSerialize = KeywordList.serialize(parsed.stream().toList(), delimiter);
assertEquals(expected, secondSerialize);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I divided afterFirstSerializeNoChangesShouldBeDoneToKeywords into two tests for better readability, but they still relly on MethodSource from other methods, is it okay to specify methodSource method in this case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say yes, to keep moving forward.

@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete and removed status: changes-required Pull requests that are not yet complete labels Dec 18, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Your pull request conflicts with the target branch.

Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line.

@github-actions github-actions Bot added status: changes-required Pull requests that are not yet complete and removed status: changes-required Pull requests that are not yet complete labels Dec 20, 2025
@github-actions github-actions Bot removed the status: changes-required Pull requests that are not yet complete label Dec 21, 2025
@calixtus

Copy link
Copy Markdown
Member

Thanks for your effort. Putting into merge queue.

@calixtus calixtus added this pull request to the merge queue Dec 22, 2025
Merged via the queue into JabRef:main with commit 08ede7f Dec 22, 2025
49 checks passed
@BOgdAnSAM-sudo BOgdAnSAM-sudo deleted the fix-for-issue-12810 branch December 23, 2025 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: keywords good second issue Issues that involve a tour of two or three interweaved components in JabRef

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement escaping for keyword separators

3 participants