fix: Support cyrillic characters #27
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue_25"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This fixes #25
Root cause of this issue is that
strings.Indexreturns byte index. So I switched the calculation of the indexes to use rune index as well as taking the string up to specified index and from specified index. Mabye the censored string could be changed to[]runeand instead of callingtakeRunesFromIndexwe could just update thecensoredinplace.@ -166,1 +177,3 @@currentIndex += foundIndex + len(word)runeIndex := g.indexToRune(s, currentIndex+foundIndex)originalIndexes = append(originalIndexes[:runeIndex], originalIndexes[runeIndex+len(word):]...)currentIndex += foundIndex + len([]rune(word))Is there any chance these three could be merged into one?
I haven't run a benchmark, but I feel this might add a noticeable overhead 🤔
@ -166,1 +177,3 @@currentIndex += foundIndex + len(word)runeIndex := g.indexToRune(s, currentIndex+foundIndex)originalIndexes = append(originalIndexes[:runeIndex], originalIndexes[runeIndex+len(word):]...)currentIndex += foundIndex + len([]rune(word))Actually, scratch that.
We may want to look into https://pkg.go.dev/unicode/utf8#DecodeRune instead:
@ -166,1 +177,3 @@currentIndex += foundIndex + len(word)runeIndex := g.indexToRune(s, currentIndex+foundIndex)originalIndexes = append(originalIndexes[:runeIndex], originalIndexes[runeIndex+len(word):]...)currentIndex += foundIndex + len([]rune(word))I added a change where we don't iterate several times, but actually just replace the rune with '*'
Codecov Report
99.40% <95.23%> (-0.60%)Continue to review full report at Codecov.
@ -166,1 +177,3 @@currentIndex += foundIndex + len(word)runeIndex := g.indexToRune(s, currentIndex+foundIndex)originalIndexes = append(originalIndexes[:runeIndex], originalIndexes[runeIndex+len(word):]...)currentIndex += foundIndex + len([]rune(word))Awesome!
Could you remove the
takeRunesFromIndexandtakeRunesToIndexfunctions then? 🙏@ -166,1 +177,3 @@currentIndex += foundIndex + len(word)runeIndex := g.indexToRune(s, currentIndex+foundIndex)originalIndexes = append(originalIndexes[:runeIndex], originalIndexes[runeIndex+len(word):]...)currentIndex += foundIndex + len([]rune(word))yep, sorry, I missed those.
Hello @TwiN I work with @martinhrvn and I have a question. Is there any future release planned? If yes can you share the date? We would like to use this fix in our code so is there any chance to release v1.6.1 ?
Thanks
@omatija I'll release it in a couple minutes; I've just been very busy these past weeks, but since you need it now, I'll accommodate you :)
Thank you for your contribution!
Released in v1.6.1
Thank you very very much! :)