This commit is contained in:
Looly 2020-05-05 23:49:41 +08:00
parent 513fb1c861
commit bf65fa3c5f
5 changed files with 22 additions and 2 deletions

View File

@ -23,6 +23,7 @@
* 【core 】 修复URLBuilder中请求参数有`&`导致的问题issue#850@Github
* 【core 】 修复URLBuilder中路径以`/`结尾导致的问题issue#I1G44J@Gitee
* 【db 】 修复SqlBuilder中orderBy无效问题issue#856@Github
* 【core 】 修复StrUtil.subBetweenAll错误问题issue#861@Github
-------------------------------------------------------------------------------------------------------------

View File

@ -1510,7 +1510,7 @@ public class StrUtil {
}
/**
* 切分字符串
* 切分字符串如果分隔符不存在则返回原字符串
*
* @param str 被切分的字符串
* @param separator 分隔符
@ -1976,11 +1976,14 @@ public class StrUtil {
* @since 5.2.5
*/
public static String[] subBetweenAll(CharSequence str, CharSequence prefix, CharSequence suffix) {
if (hasEmpty(str, prefix, suffix)) {
if (hasEmpty(str, prefix, suffix) ||
// 不包含起始字符串则肯定没有子串
false == contains(str, prefix)) {
return new String[0];
}
final List<String> result = new LinkedList<>();
final String[] split = split(str, prefix);
for (String fragment : split(str, prefix)) {
int suffixIndex = fragment.indexOf(suffix.toString());
if (suffixIndex > 0) {

View File

@ -432,5 +432,18 @@ public class StrUtilTest {
Assert.assertArrayEquals(new String[0], StrUtil.subBetweenAll("abc",null,"z"));
Assert.assertArrayEquals(new String[0], StrUtil.subBetweenAll("abc","y",null));
}
@Test
public void subBetweenAllTest2() {
//issue#861@Github起始不匹配的时候应该直接空
String src1 = "/* \n* hutool */ asdas /* \n* hutool */";
String src2 = "/ * hutool */ asdas / * hutool */";
String[] results1 = StrUtil.subBetweenAll(src1,"/**","*/");
Assert.assertEquals(0, results1.length);
String[] results2 = StrUtil.subBetweenAll(src2,"/*","*/");
Assert.assertEquals(0, results2.length);
}
}

View File

@ -35,6 +35,8 @@ public class HOTP {
/**
* 构造使用默认密码长度和默认HMAC算法(HmacSHA1)
*
* @param key 共享密码RFC 4226要求最少128位
*/
public HOTP(byte[] key) {
this(DEFAULT_PASSWORD_LENGTH, key);

View File

@ -335,6 +335,7 @@ public final class JSONUtil {
* 转为JSON字符串并写出到write
*
* @param json JSON
* @param writer Writer
* @since 5.3.3
*/
public static void toJsonStr(JSON json, Writer writer) {