Skip to content

Commit 6e3dfb5

Browse files
CopilotGoooler
andauthored
Use removePrefix instead of replace for multi-release prefix removal (#1972)
`String.replace` replaces all occurrences of the substring, not just the leading one. For multi-release JAR paths, only the leading `META-INF/versions/<n>/` prefix should be stripped before relocation. - **`ShadowCopyAction.kt`**: Replace `path.replace(multiReleasePrefix, "")` with `path.removePrefix(multiReleasePrefix)` to correctly strip only the leading prefix. ```kotlin // Before val newPath = path.replace(multiReleasePrefix, "") // After val newPath = path.removePrefix(multiReleasePrefix) ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
1 parent 49f8c31 commit 6e3dfb5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ constructor(
177177
with(fileDetails) {
178178
// Temporarily remove the multi-release prefix.
179179
val multiReleasePrefix = multiReleaseRegex.find(path)?.value.orEmpty()
180-
val newPath = path.replace(multiReleasePrefix, "")
181-
val relocatedPath = multiReleasePrefix + relocators.relocatePath(newPath)
180+
val pathSuffix = path.removePrefix(multiReleasePrefix)
181+
val relocatedPath = multiReleasePrefix + relocators.relocatePath(pathSuffix)
182182
writeToZip(entryName = relocatedPath, bytes = remapClass(relocators = relocators))
183183
}
184184
}

0 commit comments

Comments
 (0)