Skip to content

fix: use String.replace() instead of replaceFirst() in createBaseURL#1952

Merged
jeandersonbc merged 3 commits into
Adyen:mainfrom
Vinu2111:fix/service-createbaseurl-regex-dots
May 21, 2026
Merged

fix: use String.replace() instead of replaceFirst() in createBaseURL#1952
jeandersonbc merged 3 commits into
Adyen:mainfrom
Vinu2111:fix/service-createbaseurl-regex-dots

Conversation

@Vinu2111
Copy link
Copy Markdown
Contributor

Fixes #1838

What

createBaseURL in Service.java used String.replaceFirst() to swap test URLs
for live URLs. Since replaceFirst() accepts a regex pattern, dots in the URL
strings (e.g. pal-test.adyen.com) were treated as wildcards — matching any
character instead of a literal dot.

Fix

Replaced the affected replaceFirst() calls with String.replace(), which does
plain literal string matching. No regex involved, no wildcard risk.

The following blocks were updated:

  • pal- block
  • checkout- block (both the /possdk/ branch and the standard branch)
  • device-api- block (both EU and non-EU branches)

The two calls without dots (-live-test and -test-live) were
intentionally left as replaceFirst() since they are not affected by this issue.

Test

Added testLivePalUrlOnlyMatchesLiteralDots() to ServiceTest.java to verify
that a URL resembling a pal endpoint but without literal dots is not incorrectly
transformed by the pal- block.

@Vinu2111 Vinu2111 requested a review from a team as a code owner April 22, 2026 13:54
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/main/java/com/adyen/Service.java
Comment thread src/test/java/com/adyen/ServiceTest.java
@thomasc-adyen thomasc-adyen added the Fix Indicates a bug fix label May 5, 2026
@jeandersonbc jeandersonbc force-pushed the fix/service-createbaseurl-regex-dots branch from 500f7a2 to b9c4e90 Compare May 20, 2026 14:45
jeandersonbc
jeandersonbc previously approved these changes May 20, 2026
Copy link
Copy Markdown
Contributor

@jeandersonbc jeandersonbc left a comment

Choose a reason for hiding this comment

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

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!

@jeandersonbc jeandersonbc enabled auto-merge May 20, 2026 14:49
@jeandersonbc
Copy link
Copy Markdown
Contributor

@Vinu2111 could you please run mvn spotless:apply and update the branch? We recently enforced code formatting on PRs and it's currently blocking your changes.

auto-merge was automatically disabled May 21, 2026 03:27

Head branch was pushed to by a user without write access

@Vinu2111
Copy link
Copy Markdown
Contributor Author

Hi @jeandersonbc, thanks for the review! I've run mvn spotless:apply and pushed the formatting fix. Should be good to go now.

@jeandersonbc jeandersonbc enabled auto-merge May 21, 2026 07:17
@jeandersonbc jeandersonbc added this pull request to the merge queue May 21, 2026
Merged via the queue into Adyen:main with commit 3bfaf53 May 21, 2026
10 checks passed
@jeandersonbc jeandersonbc mentioned this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Indicates a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unescaped dots in replaceFirst regex patterns in Service.createBaseURL

3 participants