Skip to content

Add constant SUBSET_REGEX#700

Merged
MaximPlusov merged 2 commits intointegrationfrom
subset-regex
Apr 25, 2026
Merged

Add constant SUBSET_REGEX#700
MaximPlusov merged 2 commits intointegrationfrom
subset-regex

Conversation

@LonelyMidoriya
Copy link
Copy Markdown
Contributor

@LonelyMidoriya LonelyMidoriya commented Apr 25, 2026

Summary by CodeRabbit

  • Refactor
    • Improved code maintainability by extracting a font subset detection pattern into a reusable constant.

@LonelyMidoriya LonelyMidoriya self-assigned this Apr 25, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 25, 2026

Warning

Rate limit exceeded

@LonelyMidoriya has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 45 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 51 minutes and 45 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd3356f3-ed40-4f32-84d4-4df4eaffe109

📥 Commits

Reviewing files that changed from the base of the PR and between 90c5936 and 08c27a3.

📒 Files selected for processing (1)
  • src/main/java/org/verapdf/pd/font/PDFont.java
📝 Walkthrough

Walkthrough

A hardcoded regex pattern used for subset detection in the PDFont constructor is extracted into a new public static constant SUBSET_REGEX. The subset detection logic remains functionally unchanged, now referencing the reusable constant instead of the inline string.

Changes

Cohort / File(s) Summary
Constant Extraction
src/main/java/org/verapdf/pd/font/PDFont.java
Extracted hardcoded subset detection regex pattern into a new public static final String constant SUBSET_REGEX for reusability and maintainability.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A magic string hops from hidden to shown,
SUBSET_REGEX now claims the throne,
Constants extracted with careful paws,
Refactored with purpose, no logic flaws! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: extracting a hardcoded regex string into a new exported constant SUBSET_REGEX in the PDFont class.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch subset-regex

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/verapdf/pd/font/PDFont.java`:
- Line 50: Update the subset detection to require a literal plus and safely
strip the prefix: change SUBSET_REGEX to enforce a literal '+' (e.g.
"^[A-Z]{6}\\+.+") and replace the blind substring(7) usage with logic that finds
the '+' and uses substring(pos+1) only when the '+' is present at the expected
position (or, better, use the regex capture group to return the portion after
the '+'). Modify the code that currently calls substring(7) so it validates the
'+' exists (and is at index 6) before slicing to avoid corrupting names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 10e4c98e-127c-48f5-963b-66a5411acea2

📥 Commits

Reviewing files that changed from the base of the PR and between 6ee7742 and 90c5936.

📒 Files selected for processing (1)
  • src/main/java/org/verapdf/pd/font/PDFont.java


private static final Logger LOGGER = Logger.getLogger(PDFont.class.getCanonicalName());

public static final String SUBSET_REGEX = "^[A-Z]{6}+.+";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In Java regex, what does the quantifier {6}+mean, and does^[A-Z]{6}+.+ require a literal plus sign character?

💡 Result:

In Java regex, the quantifier {6}+ means "exactly 6 occurrences of the preceding token, possessively." It matches exactly 6 instances (like {6}) but possessively: it consumes all 6 matches greedily without backtracking if later parts of the pattern fail. This differs from the standard greedy {6} (which backtracks) and reluctant {6}? (which matches minimally). Possessive quantifiers improve performance by avoiding unnecessary backtracking attempts. The pattern ^[A-Z]{6}+.+ does NOT require a literal plus sign character. The + after {6} is part of the possessive quantifier syntax for [A-Z]{6}. The pattern matches: - ^: start of string - [A-Z]{6}+: exactly 6 uppercase letters, possessively - .+: one or more of any characters (except line terminators by default) No literal + is needed; the + is quantifier syntax, not a character to match.

Citations:


🌐 Web query:

For PDF font subset names, is the expected BaseFont format exactly six uppercase letters followed by '+' and the PostScript name (e.g., ABCDEF+FontName)?

💡 Result:

Yes, the expected BaseFont format for PDF font subsets is exactly six uppercase letters followed by '+' and the PostScript name of the original font (e.g., ABCDEF+FontName).

Citations:


Enforce literal + in subset regex to prevent false positives and font name corruption

At Line 50, the regex ^[A-Z]{6}+.+ does not enforce a literal + character as required by the PDF spec for subset fonts. This causes false positives (e.g., "ABCDEF1FontName") to match, and Line 83's substring(7) truncates them incorrectly, corrupting valid font names.

The PDF subset format requires exactly: six uppercase letters, literal +, then PostScript name (e.g., ABCDEF+FontName).

Proposed fix
-    public static final String SUBSET_REGEX = "^[A-Z]{6}+.+";
+    public static final String SUBSET_REGEX = "^[A-Z]{6}\\+.+";

Also applies to: 83-83

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/verapdf/pd/font/PDFont.java` at line 50, Update the subset
detection to require a literal plus and safely strip the prefix: change
SUBSET_REGEX to enforce a literal '+' (e.g. "^[A-Z]{6}\\+.+") and replace the
blind substring(7) usage with logic that finds the '+' and uses substring(pos+1)
only when the '+' is present at the expected position (or, better, use the regex
capture group to return the portion after the '+'). Modify the code that
currently calls substring(7) so it validates the '+' exists (and is at index 6)
before slicing to avoid corrupting names.

@MaximPlusov MaximPlusov merged commit c60d70c into integration Apr 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants