bug: incorrect position replaced #46

Open
opened 2023-01-15 22:43:49 -05:00 by IAD · 0 comments
IAD commented 2023-01-15 22:43:49 -05:00 (Migrated from github.com)

Describe the bug

version: 1.6.9
test:


import (
	"testing"

	goaway "github.com/TwiN/go-away"
	"github.com/stretchr/testify/require"
)

func TestDefaultDriver_AR_4768(t *testing.T) {
	detector := goaway.NewProfanityDetector().WithCustomDictionary(
		[]string{"anal", "babi"}, // profanities
		[]string{"babibu"},       // falsePositives
		[]string{"babibube"},     // falseNegatives
	)

	message := "message with old anal new babi falsePositive babibu falseNegative babibube"
	expected := "message with old **** new **** falsePositive babibu falseNegative ********"

	isProfane := detector.IsProfane(message)
	require.True(t, isProfane)

	censored := detector.Censor(message)
	require.Equal(t, expected, censored)

	/*
		Original :message with old anal new babi falsePositive babibu falseNegative babibube
		Expected :message with old **** new **** falsePositive babibu falseNegative ********
		Actual   :message with old anal ne* ***i fa****ositive babibu falseNegative ********
	*/
}

What do you see?

message with old **** new **** falsePositive babibu falseNegative ********

What do you expect to see?

message with old **** new **** falsePositive babibu falseNegative ********

List the steps that must be taken to reproduce this issue

use the test from the description

Version

v1.6.9

Additional information

No response

### Describe the bug version: 1.6.9 test: ```package driver_test import ( "testing" goaway "github.com/TwiN/go-away" "github.com/stretchr/testify/require" ) func TestDefaultDriver_AR_4768(t *testing.T) { detector := goaway.NewProfanityDetector().WithCustomDictionary( []string{"anal", "babi"}, // profanities []string{"babibu"}, // falsePositives []string{"babibube"}, // falseNegatives ) message := "message with old anal new babi falsePositive babibu falseNegative babibube" expected := "message with old **** new **** falsePositive babibu falseNegative ********" isProfane := detector.IsProfane(message) require.True(t, isProfane) censored := detector.Censor(message) require.Equal(t, expected, censored) /* Original :message with old anal new babi falsePositive babibu falseNegative babibube Expected :message with old **** new **** falsePositive babibu falseNegative ******** Actual :message with old anal ne* ***i fa****ositive babibu falseNegative ******** */ } ``` ### What do you see? message with old **** new **** falsePositive babibu falseNegative ******** ### What do you expect to see? message with old **** new **** falsePositive babibu falseNegative ******** ### List the steps that must be taken to reproduce this issue use the test from the description ### Version v1.6.9 ### Additional information _No response_
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
TwiN/go-away#46
No description provided.