Allow suffix letter after the numbers in page range#15362
Allow suffix letter after the numbers in page range#15362subhramit merged 4 commits intoJabRef:mainfrom
Conversation
Relax the page checker regex so that suffix letters are accepted such as "436S-439S". Add unit tests for valid and invalid suffix cases, and update the changelog.
Review Summary by QodoAllow suffix letters in page range validation
WalkthroughsDescription• Relaxed page range regex to accept suffix letters like "436S-439S" • Updated SINGLE_PAGE_PATTERN to allow optional suffix after numbers • Added comprehensive unit tests for valid and invalid suffix cases • Updated changelog to document the fix Diagramflowchart LR
A["SINGLE_PAGE_PATTERN<br/>Old: [A-Za-z]?\\d*"] -->|"Add suffix support"| B["SINGLE_PAGE_PATTERN<br/>New: [A-Za-z]?\\d*[A-Za-z]?"]
B -->|"Validates"| C["Page ranges<br/>436S-439S"]
D["Unit Tests"] -->|"Added cases"| E["Valid: 436S-439S<br/>Invalid: 436SS-439S"]
File Changes1. jablib/src/main/java/org/jabref/logic/integrity/PagesChecker.java
|
Code Review by Qodo
1. Letter-only pages accepted
|
| public class PagesChecker implements ValueChecker { | ||
|
|
||
| private static final String SINGLE_PAGE_PATTERN = "[A-Za-z]?\\d*"; // optional prefix and number | ||
| private static final String SINGLE_PAGE_PATTERN = "[A-Za-z]?\\d*[A-Za-z]?"; // optional prefix, numbers, and optional suffix |
There was a problem hiding this comment.
1. Letter-only pages accepted 🐞 Bug ✓ Correctness
PagesChecker's updated SINGLE_PAGE_PATTERN allows page tokens with no digits when both the optional prefix and optional suffix letters are present (e.g., "SS"), so integrity checking can silently accept malformed page ranges like "SS-SS". This exceeds the documented intent of validating “page numbers or range of numbers”.
Agent Prompt
### Issue description
`PagesChecker` now treats letter-only page tokens like `"SS"` as valid because `SINGLE_PAGE_PATTERN` allows an optional prefix letter + zero digits + an optional suffix letter. This can hide malformed page values from the integrity checker.
### Issue Context
The checker is documented to validate “page numbers or range of numbers”. We still want to accept suffix letters after digits (e.g., `436S-439S`) without opening the door to prefix+suffix with no digits.
### Fix approach (suggested)
- Change `SINGLE_PAGE_PATTERN` to an alternation that:
- allows the legacy prefix-only form (`[A-Za-z]?\d*`) to preserve current behavior for `43+` handling, but
- only allows a suffix letter when at least one digit exists.
For example:
```java
private static final String SINGLE_PAGE_PATTERN = "(?:[A-Za-z]?\\d+[A-Za-z]?|[A-Za-z]?\\d*)";
```
This preserves numeric pages and `43+` behavior, allows `436S`, but rejects `SS`.
- Add unit tests to ensure `"SS"` is rejected in both modes (and optionally `"SS-SS"`/`"SS--SS"`).
### Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/integrity/PagesChecker.java[14-35]
- jablib/src/test/java/org/jabref/logic/integrity/PagesCheckerBiblatexTest.java[29-65]
- jablib/src/test/java/org/jabref/logic/integrity/PagesCheckerBibtexTest.java[29-65]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
This comment has been minimized.
This comment has been minimized.
|
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. |
|
/assign-me |
|
Hi Saurabh, I am still working on this issue. |
| public class PagesChecker implements ValueChecker { | ||
|
|
||
| private static final String SINGLE_PAGE_PATTERN = "[A-Za-z]?\\d*"; // optional prefix and number | ||
| private static final String SINGLE_PAGE_PATTERN = "[A-Za-z]?\\d*[A-Za-z]?"; // optional prefix, numbers, and optional suffix |
There was a problem hiding this comment.
please align the comment with the ones below
This comment has been minimized.
This comment has been minimized.
✅ All tests passed ✅🏷️ Commit: ff179b7 Learn more about TestLens at testlens.app. |
|
@subhramit Hi, thanks for the approval. I am a bit confused about the current state of the PR. I have resolved the changelog conflicts locally, but I have not pushed that merge yet. Should I still push the changes or it is already handled by the auto-merge? Thanks so much for your guidance! |
I took the opportunity to resolve it as this PR has been pending for 2 weeks. |
|
Got it! Thanks for resolving it. |
Relax the page checker regex so that suffix letters are accepted such as "436S-439S".
Related issues and pull requests
Closes #13701
PR Description
Change
SINGLE_PAGE_PATTERNto allow suffix letter after the numbers. Update the unit test for both valid and invalid cases.Steps to test
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)