Skip to content

Reject over-length codes in ISSNCheckDigit#426

Merged
garydgregory merged 1 commit into
apache:masterfrom
sahvx655-wq:issn-reject-over-length
Jul 17, 2026
Merged

Reject over-length codes in ISSNCheckDigit#426
garydgregory merged 1 commit into
apache:masterfrom
sahvx655-wq:issn-reject-over-length

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor

Noticed while exercising the check digit routines directly rather than through their wrapper validators.

  1. ISSNCheckDigit.ISSN_CHECK_DIGIT.isValid is a public entry point and ModulusCheckDigit never checks the code length, so an over-length string reaches the modulus test unchecked.
  2. weightedValue weights each position by 9 - leftPos, so a ninth character lands on weight zero and contributes nothing; appending any character to a valid numeric ISSN (031784710..031784719, 0317847100) still returns true, though only the eight-character 03178471 is a real ISSN.
  3. Guarded isValid to require the fixed eight-character length before the check digit test, the same shape as the existing IBANCheckDigit length guard; the ISSNValidator/CodeValidator path already enforces length, so valid input is unaffected.

Regression test testOverLengthRejected added, which fails on the current code and passes with the guard.

@garydgregory garydgregory changed the title reject over-length codes in ISSNCheckDigit Reject over-length codes in ISSNCheckDigit Jul 17, 2026
@garydgregory

Copy link
Copy Markdown
Member

@sahvx655-wq
See my comment #423 (review)

@garydgregory
garydgregory merged commit 57fbed0 into apache:master Jul 17, 2026
10 checks passed
@garydgregory

Copy link
Copy Markdown
Member

Thank you @sahvx655-wq , merged 🚀 Please check for other length issues in this package.

@sahvx655-wq

Copy link
Copy Markdown
Contributor Author

Will do. From a quick look the mirror form exists in the rightPos-weighted routines: ISBN10CheckDigit and ABANumberCheckDigit have no length check either, and there a prepended zero is the character that lands on a no-op weight, so a leading-zero-padded code keeps the same sum. I'll work through the package and put up fixes for the ones reachable outside their wrapper validators. Thanks for merging this.

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