Skip to content

Fix placeholder corruption and improve classpath boundary checks - #377

Open
mercyblitz wants to merge 5 commits into
mainfrom
workbuddy/main-382959a6
Open

mercyblitz wants to merge 5 commits into
mainfrom
workbuddy/main-382959a6

Conversation

@mercyblitz

Copy link
Copy Markdown
Contributor

This pull request addresses two main areas: it improves the robustness of class path matching in URLUtils to avoid false positives, and fixes an issue in string formatting where argument values containing placeholders could be incorrectly replaced. Comprehensive regression tests have been added for both issues.

Class Path Matching Improvements:

  • Introduced the isResourcePathOnClassPath method in URLUtils, which uses canonical paths and path-separator boundaries to accurately determine if a resource is under a class path, preventing false matches like /opt/app matching /opt/application. Updated resolveArchiveDirectory to use this method.
  • Added extensive unit tests in URLUtilsTest to verify correct behavior for various path cases, including real file system paths and edge cases.

String Formatting Fixes:

  • Modified FormatUtils.formatWithPlaceholder so that argument values containing the placeholder (e.g. "x{}y") are not corrupted by subsequent replacements, by tracking the replacement cursor.
  • Added regression tests in FormatUtilsTest to ensure placeholders inside argument values are handled correctly, including cases with more placeholders than arguments and custom placeholders.

Other Minor Updates:

  • Added missing imports in test and source files for new functionality. [1] [2] [3]

Update `FormatUtils` replacement logic to search after each inserted value, preventing argument values containing placeholders from being replaced by later arguments. Add regression coverage for default and custom placeholders.
Replaced substring-based classpath matching with canonical path boundary checks when resolving archive directories, preventing false positives like "/opt/app" matching "/opt/application". Added focused regression tests for issue #318, including canonical path normalization cases, real temp-directory paths, and archive directory resolution behavior for both classpath and non-classpath resources.
Copilot AI balanced review requested due to automatic review settings November 30, 2026 15:13
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ore/src/main/java/io/microsphere/net/URLUtils.java 75.00% 2 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ Complexity Δ
.../net/CompositeSubProtocolURLConnectionFactory.java 100.00% <100.00%> (ø) 19.00 <0.00> (+2.00)
...src/main/java/io/microsphere/text/FormatUtils.java 100.00% <100.00%> (ø) 6.00 <0.00> (ø)
...ore/src/main/java/io/microsphere/net/URLUtils.java 99.08% <75.00%> (-0.92%) 139.00 <6.00> (+6.00) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Classpath matching regressions cause resolveArchiveFile to return null for valid resources under filesystem-root classpaths and Windows file URLs, requiring path normalization fixes and regression tests.

2 open issues
What changed in this PR

This PR improves core utility behavior by preserving placeholders inside formatting arguments and tightening classpath matching to avoid false prefix matches.

Changes:

  • Track the formatting cursor so inserted argument values are not processed again.
  • Match canonical resource and classpath paths using separator boundaries.
  • Add regression tests for placeholder preservation and classpath matching.
File Description
microsphere-java-core/​src/​test/​java/​io/​microsphere/​text/​FormatUtilsTest.java Tests embedded placeholders, remaining placeholders, and custom markers.
microsphere-java-core/​src/​test/​java/​io/​microsphere/​net/​URLUtilsTest.java Tests path boundaries, canonicalization, and archive-directory resolution.
microsphere-java-core/​src/​main/​java/​io/​microsphere/​text/​FormatUtils.java Advances the search cursor past each inserted argument.
microsphere-java-core/​src/​main/​java/​io/​microsphere/​net/​URLUtils.java Introduces canonical, boundary-aware classpath matching.

Review effort: Balanced

File archiveDirectory = null;
for (String classPath : classPaths) {
if (resourcePath.contains(classPath)) {
if (isResourcePathOnClassPath(resourcePath, classPath)) {
mercyblitz and others added 2 commits November 30, 2026 23:16
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 15:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the classpath-boundary and placeholder-preservation changes.

1 open issue
1 resolved since last review

Review effort: Balanced

…ects/microsphere-java into workbuddy/main-382959a6
Copilot AI balanced review requested due to automatic review settings November 30, 2026 15:22
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

File URL paths are canonicalized without decoding, causing valid resources in space-containing directories to be rejected and encoded parent-directory segments to incorrectly match the classpath.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Decode file URLs before canonicalizing classpath paths

microsphere-java-core/​src/​main/​java/​io/​microsphere/​net/​URLUtils.java:299

With relative classpath classes and working directory /tmp/my app, buildPath(resourceURL) supplies /tmp/my%20app/classes/Foo.class; canonicalization leaves %20 intact, so the new comparison rejects a valid resource and resolveArchiveFile() returns null. The same encoding mismatch lets /opt/app/%2e%2e/application/Foo.class incorrectly match classpath /opt/app. Convert the file URL to a decoded filesystem path before canonicalizing, preserving literal + characters, and add regression tests for escaped parent directories and encoded .. segments.

Review effort: Balanced

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