From 7a2b86a4bf54aac7dd45249f5bff6b9b955ae19b Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 26 Dec 2025 00:14:55 +0800 Subject: [PATCH] fix bug --- .../java/cn/hutool/core/text/CharSequenceUtil.java | 14 +++++++++----- hutool-log/pom.xml | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java b/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java index 199c89e77f..932dc8c2fd 100755 --- a/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/text/CharSequenceUtil.java @@ -4784,18 +4784,22 @@ public class CharSequenceUtil { throw new IndexOutOfBoundsException("Invalid range: [" + startInclude + ", " + endExclude + ")"); } + if (Math.abs(moveLength) > len) { + // 循环位移,当越界时循环 + moveLength = moveLength % len; + } // 分离“移动块”和“剩余轨道” - String block = str.subSequence(startInclude, endExclude).toString(); - String rest = new StringBuilder(str).delete(startInclude, endExclude).toString(); + final String block = str.subSequence(startInclude, endExclude).toString(); + final String rest = new StringBuilder(str).delete(startInclude, endExclude).toString(); - int restLen = rest.length(); + final int restLen = rest.length(); if (restLen == 0) { return str.toString(); // 全选时位移无意义 } // 计算循环周期:剩余字符数 + 1(代表块可以存在的不同位置点) - int totalPositions = restLen + 1; + final int totalPositions = restLen + 1; // 计算移动后的新位置 (处理正负数) - int newPos = (startInclude + moveLength % totalPositions + totalPositions) % totalPositions; + final int newPos = (startInclude + moveLength % totalPositions + totalPositions) % totalPositions; // 重新组装 return rest.substring(0, newPos) + // 放入新位置前的剩余字符 block + // 放入整体块 diff --git a/hutool-log/pom.xml b/hutool-log/pom.xml index 915385ab00..2cdf685599 100755 --- a/hutool-log/pom.xml +++ b/hutool-log/pom.xml @@ -23,7 +23,7 @@ 1.7.36 1.4.14 1.2.17 - 2.20.0 + 2.25.3 1.3.3 1.3.6 2.7.0