Fix: Prevent creating empty or duplicate fields #15168
Conversation
Review Summary by QodoPrevent empty, duplicate, and invalid field creation in custom entry types
WalkthroughsDescription• Prevent creation of empty fields and fields containing spaces with validation • Prevent duplicate field creation using case-insensitive comparison • Capitalize first letter of custom field names in display • Scroll to and highlight newly added fields in the UI File Changes1. jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java
|
Code Review by Qodo
✅ 1.
|
✅ All tests passed ✅🏷️ Commit: 6d903ba Learn more about TestLens at testlens.app. |
|
|
||
| assertEquals(""" | ||
| entry type,citation key,custom,Pages,Title | ||
| entry type,citation key,Custom,Pages,Title |
There was a problem hiding this comment.
Are these changes related and needed?
There was a problem hiding this comment.
Yes, now when a field is created, its first letter is capitalized like entry type. If dont change this code, tests will not pass
There was a problem hiding this comment.
But fields should always be lowercase !
There was a problem hiding this comment.
But fields should always be lowercase !
Got it, i'll fix it now
There was a problem hiding this comment.
@koppor Just for clarification: Do we lowercase fields always?
There was a problem hiding this comment.
Yes, for standardfields, customizable for custom fields: "Hardcode StandardField names and use exact or customized names otherwise". We have an ADR: https://devdocs.jabref.org/decisions/0049-hardcode-fieldnames.html#decision-outcome
Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
|
I checked the error output but it seems not related to the part I modified. |
|
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. |
* refs/heads/main: Increase max assignments from 2 to 3 Chore(deps): Bump io.zonky.test:embedded-postgres in /versions (#15213) Chore(deps): Bump jablib/src/main/resources/csl-styles (#15211) New Crowdin updates (#15208) Fix: Prevent creating empty or duplicate fields (#15168) chore(deps): update jackson monorepo to v3.1.0 (#15203) Update KeywordEditor to work with escaping (#14929) Chore(deps): Bump com.dlsc.gemsfx:gemsfx in /versions (#15205) Chore(deps): Bump tools.jackson:jackson-bom in /versions (#15206) Fix: Reset External File Type to default (#15167) docs: fix link formatting in ADR 0012 (#15201)
* Prevent empty fields * Prevent duplicate fields * add CHANGELOG.md * scroll to newly added fields * fix test fails * fix test fails * fix test fails * fix test fails * Apply suggestion from @subhramit Co-authored-by: Subhramit Basu <subhramit.bb@live.in> * custom fields should be lowercase * explicit viewmodel name * update CHANGELOG.md * Apply suggestion from @subhramit --------- Co-authored-by: Subhramit Basu <subhramit.bb@live.in> Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
* Prevent empty fields * Prevent duplicate fields * add CHANGELOG.md * scroll to newly added fields * fix test fails * fix test fails * fix test fails * fix test fails * Apply suggestion from @subhramit Co-authored-by: Subhramit Basu <subhramit.bb@live.in> * custom fields should be lowercase * explicit viewmodel name * update CHANGELOG.md * Apply suggestion from @subhramit --------- Co-authored-by: Subhramit Basu <subhramit.bb@live.in> Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Related issues and pull requests
Closes #15130
PR Description
This PR addresses the issue where empty and duplicate fields can be created. When checking duplication, use
equalsIgnoreCaseinstead ofequals. After creating a new field, it will scroll to and highlight newly added field.Required verification screenshot:

Steps to test
Open File -> Preference -> Entry types
Select an entry type, type some spaces or a string with spaces (e.g. "te st") or leave field empty. Click "+" or press enter.
Expected result: No fields are created, JabRef warns users "Fields cannot be empty and must not contain spaces."
Type "test" and save. Then type "test" again, click "+" or press enter.
Expected result: A pop-up warning shows up: You added field "test" twice. Only one will be kept.
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)