fix: use String.replace() instead of replaceFirst() in createBaseURL#1952
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces replaceFirst with replace in Service.java to ensure literal matching of URLs containing dots, and adds a corresponding unit test. The review feedback suggests extending this change to the authe block for consistency and improving the test case to accurately verify that dots are not treated as regex wildcards.
500f7a2 to
b9c4e90
Compare
jeandersonbc
left a comment
There was a problem hiding this comment.
Hi @Vinu2111, changes look good! I considered asking to update the PR to use .replace across the other places in createBaseURL for consistency but I don't think it's necessary and it's unknown whether this would create some issue. I'm approving the PR as-is. Thanks for the contribution!
|
@Vinu2111 could you please run |
Head branch was pushed to by a user without write access
|
Hi @jeandersonbc, thanks for the review! I've run mvn spotless:apply and pushed the formatting fix. Should be good to go now. |
Fixes #1838
What
createBaseURLinService.javausedString.replaceFirst()to swap test URLsfor live URLs. Since
replaceFirst()accepts a regex pattern, dots in the URLstrings (e.g.
pal-test.adyen.com) were treated as wildcards — matching anycharacter instead of a literal dot.
Fix
Replaced the affected
replaceFirst()calls withString.replace(), which doesplain literal string matching. No regex involved, no wildcard risk.
The following blocks were updated:
pal-blockcheckout-block (both the/possdk/branch and the standard branch)device-api-block (both EU and non-EU branches)The two calls without dots (
-live→-testand-test→-live) wereintentionally left as
replaceFirst()since they are not affected by this issue.Test
Added
testLivePalUrlOnlyMatchesLiteralDots()toServiceTest.javato verifythat a URL resembling a pal endpoint but without literal dots is not incorrectly
transformed by the
pal-block.