修复StrBuilderinsert插入计算错误问题(issue#ICTSRZ@Gitee)

This commit is contained in:
Looly
2025-08-20 11:57:22 +08:00
parent 3d304f6168
commit d84682e7c8
3 changed files with 23 additions and 7 deletions

View File

@@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.40(2025-08-19)
# 5.8.40(2025-08-20)
### 🐣新特性
* 【captcha】 `MathGenerator`四则运算方式支持不生成负数结果pr#1363@Gitee
@@ -19,6 +19,7 @@
* 【core 】 修复`ChineseDate `闰年闰月节日获取问题issue#ICL1BT@Gitee
* 【core 】 修复`TreeBuilder`append重复向idTreeMap中put问题pr#3992@Github
* 【extra 】 修复`QLExpressEngine`allowClassSet无效问题issue#3994@Github
* 【core 】 修复`StrBuilder`insert插入计算错误问题issue#ICTSRZ@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.39(2025-06-20)

View File

@@ -271,7 +271,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
} else if (csq instanceof StrBuilder) {
((StrBuilder) csq).getChars(0, len, this.value, index);
} else {
for (int i = 0, j = this.position; i < len; i++, j++) {
for (int i = 0, j = index; i < len; i++, j++) {
this.value[j] = csq.charAt(i);
}
}
@@ -316,7 +316,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
final int length = end - start;
moveDataAfterIndex(index, length);
for (int i = start, j = this.position; i < end; i++, j++) {
for (int i = start, j = index; i < end; i++, j++) {
value[j] = csq.charAt(i);
}
this.position = Math.max(this.position, index) + length;

View File

@@ -1,12 +1,13 @@
package cn.hutool.core.text;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* StrBuilder单元测试
@@ -116,4 +117,18 @@ public class StrBuilderTest {
builder = strBuilder.delTo(0);
assertEquals("", builder.toString());
}
@Test
void issueICTSRZTest() {
final StrBuilder helloWorld = StrBuilder.create("Hello World");
helloWorld.insert(6, "Beautiful ", 0, 10);
Assertions.assertEquals("Hello Beautiful World", helloWorld.toString());
}
@Test
void issueICTSRZTest2() {
final StrBuilder helloWorld = StrBuilder.create("Hello World");
helloWorld.insert(6, "Beautiful ");
Assertions.assertEquals("Hello Beautiful World", helloWorld.toString());
}
}