Skip to content

Commit cd026fb

Browse files
committed
refactor: simplify censor_string() implementation
1 parent 9fc7f21 commit cd026fb

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

ggshield/core/filter.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,12 @@ def censor_string(text: str) -> str:
121121
if len_match == 3:
122122
return f"**{text[2]}"
123123

124-
start_privy_len = min(math.ceil(len_match / 6), MAXIMUM_CENSOR_LENGTH)
125-
end_privy_len = len_match - min(math.ceil(len_match / 6), MAXIMUM_CENSOR_LENGTH)
124+
censor_start = min(math.ceil(len_match / 6), MAXIMUM_CENSOR_LENGTH)
125+
censor_end = len_match - censor_start
126126

127127
censored = REGEX_MATCH_HIDE.sub("*", text)
128128

129-
return str(
130-
text[:start_privy_len]
131-
+ censored[start_privy_len:end_privy_len]
132-
+ text[end_privy_len:]
133-
)
129+
return text[:censor_start] + censored[censor_start:censor_end] + text[censor_end:]
134130

135131

136132
def censor_match(match: Match) -> str:

0 commit comments

Comments
 (0)