Repository navigation
ACOMMONS-217 Introduce shared IP address extraction with IpAddressExtractor - #573
Conversation
fb5fb16 to
874419b
Compare
IpAddressExtractor
c218252 to
de9f436
Compare
de9f436 to
77e3a1a
Compare
guillem-bartrina-sonarsource
left a comment
There was a problem hiding this comment.
I believe it is a good idea to standardize the extraction of IP addresses from literals. However, I am not convinced of the coupling with the IpAddressClassifier. I believe there should be a separation of concerns.
Note that ParsedIp is an internal class of the latter, produced by its parse functionality. The extractor is concerned with extracting the slice corresponding to an IP address from a more complex structure. It just so happens to wrap its final result with a call to parse. Notice that you had to add the literal field in ParsedIp just to be able to retrieve the result of the extractor.
To me, it would be clearer if the extractor just extracted the IP address from the literal; the users of the API could then call the classifier if they want to classify it. It is a simple composition on the user's side, and you could remove the literal field from ParsedIp.
WDYT?
|
Thanks for the thorough review.
I agree, I didn’t like the coupling either. Given the name To avoid duplicating IP address validation logic, I reused One option would be to extract the validation and parsing logic, along with the parsed representation, into a separate class shared by A simpler alternative would be to name it I'm inclined to go with the latter, though it feels uglier. WDYT? |
I'd go with the latter as well, even if it is a bit ugly. Maybe @teemu-rytilahti-sonarsource has some input. |
There was a problem hiding this comment.
Just a couple of nits from a very quick review, but it is looking good already, thanks @lijun-chen-sonarsource!
The PR title and the desc need an update after the refactoring & renaming.
guillem-bartrina-sonarsource
left a comment
There was a problem hiding this comment.
LGTM from my side, after addressing the other review comments
…inning and bails out on any error
36c5f6f to
3235922
Compare
Code Review ✅ Approved 3 closed / 3 findings🟡 Medium risk · Introducing shared IP-candidate extraction with URL, endpoint, and CIDR heuristics could select unintended address text for consumers to classify. Adds One open minor finding: the ✅ 3 closed✅ Edge Case: Endpoint with port treats a numeric path as a CIDR suffix
✅ Edge Case: Unlisted delimiters cut off malformed candidates, so 1.2.3.4~foo is accepted
Closed: Quality: Javadoc omits the new five-character port limit
Verification Rules 2/2 met Repos 12 inspected · PRs 2 inspectedFunctional validation No results Rules 2 passed 1 not applicable
Broader impact Repos 12 inspected PRs 2 inspectedCross-repo 12 repositories inspected 0 open impacts
7 more repositories Cross-PR 2 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Add
IpAddressExtractorso PHP, Go, Kotlin, and other analyzers can reuse consistent extraction behavior for bare addresses, endpoints, and URLs.The implementation is extracted from sonar-php PR #1848, with these additions:
Optional<ParsedIp>, allowing callers to query classification directly.ParsedIp.literal()preserves the extracted spelling for analyzer-specific filters.+,-, and., and skip optional URL user information such asuser:pass@.1.2.3.4:8080/33yields1.2.3.4, while bare CIDRs retain their prefix for validation and classification.Stack created with GitHub Stacks CLI • Give Feedback 💬
Summary by Gitar
IpAddressExtractortoIpAddressCandidateExtractorand removed its dependency onIpAddressClassifierextractreturnsOptional<String>candidates instead ofOptional<ParsedIp>, leaving validation toIpAddressClassifier.parseThis will update automatically on new commits.