Skip to content

fix: make URLToStringConversion generate URI.create(String).toURL() instead of new url(/Education?url=https%3A%2F%2Fgithub.com%2Fmapstruct%2Fmapstruct%2Fpull%2FString)#4044

Open
yvasyliev wants to merge 1 commit into
mapstruct:mainfrom
yvasyliev:bugfix/string-to-url-conversion

Conversation

@yvasyliev
Copy link
Copy Markdown

This pull request refactors the handling of URL conversions in the codebase, standardizing the approach by using URI.create(...).toURL() instead of direct new url(/Education?url=https%3A%2F%2Fgithub.com%2Fmapstruct%2Fmapstruct%2Fpull%2F...) construction. This change affects both the internal conversion logic and the related tests, aiming for improved consistency and reliability in URL handling.

Refactoring of URL Conversion Logic:

  • The ConversionUtils.url method and related imports of java.net.URL were removed, and all references were updated to use URI and the ConversionUtils.uri method instead.
  • In URLToStringConversion.java, the conversion now constructs URLs using URI.create(<SOURCE>).toURL() rather than new url(/Education?url=https%3A%2F%2Fgithub.com%2Fmapstruct%2Fmapstruct%2Fpull%2F%26lt%3BSOURCE%26gt%3B). This also updates the import types from URL to URI.

Test Adjustments for New Conversion Approach:

  • In URLConversionTest.java, all usages of new url(/Education?url=https%3A%2F%2Fgithub.com%2Fmapstruct%2Fmapstruct%2Fpull%2F...) were replaced with URI.create(...).toURL() to match the new conversion logic.
  • Test cases for invalid URL strings were updated to use malformed URI schemes (e.g., "xxxxxx://mapstruct.org/") instead of arbitrary invalid strings, ensuring the tests accurately reflect the new conversion path.

Closes #4041

…)` instead of `new url(/Education?url=https%3A%2F%2Fgithub.com%2Fmapstruct%2Fmapstruct%2Fpull%2FString)`
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.

URL conversion uses deprecated constructor new url(/Education?url=https%3A%2F%2Fgithub.com%2Fmapstruct%2Fmapstruct%2Fpull%2FString) in Java 20+

1 participant