Commit 0e07da807a266cf98af18ea4c98023f7e66904d6
Merge branch 'master-jdk17' of https://github.com/YunaiV/ruoyi-vue-pro into master-jdk17
Showing
1 changed file
with
5 additions
and
14 deletions
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/desensitize/core/slider/handler/AbstractSliderDesensitizationHandler.java
| ... | ... | @@ -26,19 +26,14 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation> |
| 26 | 26 | int suffixKeep = getSuffixKeep(annotation); |
| 27 | 27 | String replacer = getReplacer(annotation); |
| 28 | 28 | int length = origin.length(); |
| 29 | + int interval = length - prefixKeep - suffixKeep; | |
| 29 | 30 | |
| 30 | - // 情况一:原始字符串长度小于等于保留长度,则原始字符串全部替换 | |
| 31 | - if (prefixKeep >= length || suffixKeep >= length) { | |
| 32 | - return buildReplacerByLength(replacer, length); | |
| 33 | - } | |
| 34 | - | |
| 35 | - // 情况二:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换 | |
| 36 | - if ((prefixKeep + suffixKeep) >= length) { | |
| 31 | + // 情况一:原始字符串长度小于等于前后缀保留字符串长度,则原始字符串全部替换 | |
| 32 | + if (interval <= 0) { | |
| 37 | 33 | return buildReplacerByLength(replacer, length); |
| 38 | 34 | } |
| 39 | 35 | |
| 40 | - // 情况三:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串 | |
| 41 | - int interval = length - prefixKeep - suffixKeep; | |
| 36 | + // 情况二:原始字符串长度大于前后缀保留字符串长度,则替换中间字符串 | |
| 42 | 37 | return origin.substring(0, prefixKeep) + |
| 43 | 38 | buildReplacerByLength(replacer, interval) + |
| 44 | 39 | origin.substring(prefixKeep + interval); |
| ... | ... | @@ -52,11 +47,7 @@ public abstract class AbstractSliderDesensitizationHandler<T extends Annotation> |
| 52 | 47 | * @return 构建后的替换符 |
| 53 | 48 | */ |
| 54 | 49 | private String buildReplacerByLength(String replacer, int length) { |
| 55 | - StringBuilder builder = new StringBuilder(); | |
| 56 | - for (int i = 0; i < length; i++) { | |
| 57 | - builder.append(replacer); | |
| 58 | - } | |
| 59 | - return builder.toString(); | |
| 50 | + return replacer.repeat(length); | |
| 60 | 51 | } |
| 61 | 52 | |
| 62 | 53 | /** | ... | ... |