Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PI-2536 Fix NumberFormatException attempting to parse invalid PNCs #754

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

marcus-bcl
Copy link
Contributor

PNC IDs can only have up to 7 digits after the slash, but the existing regular expression allows an unlimited number.

Example invalid PNC ID: 1999/9999999999a. Previously the code would try to parse 9,999,999,999 as an int, and fail.

PNC IDs can only have up to 7 digits after the slash, but the existing regular expression allows an unlimited number.

Example invalid PNC ID: 1999/9999999999a. Previously the code would try to parse 9,999,999,999 as an int, and fail.
@marcus-bcl marcus-bcl requested a review from a team as a code owner September 26, 2024 16:43
@@ -40,5 +40,6 @@ internal class CanonicalPncKtTest {
assertThat("SF68/945674U".canonicalPNCNumber()).isEqualTo("SF68/945674U")
assertThat("".canonicalPNCNumber()).isEqualTo("")
assertThat("2010/BBBBBBBA".canonicalPNCNumber()).isEqualTo("2010/BBBBBBBA")
assertThat("2003/012345678A".canonicalPNCNumber()).isEqualTo("2003/012345678A")

Choose a reason for hiding this comment

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

tests in this class would be a good candidate for using ParamitizedTest

Choose a reason for hiding this comment

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

@ParameterizedTest
@CsvSource(
"2003/1234567A,2003/1234567a",
"2003/0234567A,2003/234567a"
)
internal fun will convert to canonical form of PNC when it is valid(pnc: String, expectedCrn: String) {
assertThat(pnc.canonicalPNCNumber()).isEqualTo(expectedCrn)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cheers - I've updated that to be a parameterized test. @achimber-moj could I get another review?

achimber-moj
achimber-moj previously approved these changes Sep 26, 2024
@marcus-bcl marcus-bcl merged commit ca8c3d3 into main Sep 27, 2024
4 checks passed
@marcus-bcl marcus-bcl deleted the PI-2536-pnc-overflow branch September 27, 2024 11:27
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