mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 10:18:28 +09:00
Merge pull request #1351 from anyproto/go-3609-anonymize-link-marks
GO-3609 Anonymize link marks in text blocks
This commit is contained in:
commit
475361364c
2 changed files with 34 additions and 3 deletions
|
@ -103,6 +103,11 @@ func Event(e *pb.EventMessage) (res *pb.EventMessage) {
|
|||
case *pb.EventMessageValueOfBlockSetText:
|
||||
if v.BlockSetText.Text != nil {
|
||||
v.BlockSetText.Text.Value = Text(v.BlockSetText.Text.Value)
|
||||
if v.BlockSetText.Marks != nil && v.BlockSetText.Marks.Value != nil {
|
||||
for i, mark := range v.BlockSetText.Marks.Value.Marks {
|
||||
v.BlockSetText.Marks.Value.Marks[i].Param = Text(mark.Param)
|
||||
}
|
||||
}
|
||||
}
|
||||
case *pb.EventMessageValueOfBlockSetFile:
|
||||
if v.BlockSetFile.Name != nil {
|
||||
|
|
|
@ -34,6 +34,12 @@ func TestChange(t *testing.T) {
|
|||
Content: &model.BlockContentOfText{
|
||||
Text: &model.BlockContentText{
|
||||
Text: "block create text",
|
||||
Marks: &model.BlockContentTextMarks{
|
||||
Marks: []*model.BlockContentTextMark{{
|
||||
Param: "https://randomsite.com/kosilica",
|
||||
Type: model.BlockContentTextMark_Link,
|
||||
}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -43,9 +49,18 @@ func TestChange(t *testing.T) {
|
|||
},
|
||||
changeUpdate(&pb.EventMessage{
|
||||
Value: &pb.EventMessageValueOfBlockSetText{
|
||||
BlockSetText: &pb.EventBlockSetText{Id: "text", Text: &pb.EventBlockSetTextText{
|
||||
Value: "set text event",
|
||||
}},
|
||||
BlockSetText: &pb.EventBlockSetText{
|
||||
Id: "text",
|
||||
Text: &pb.EventBlockSetTextText{
|
||||
Value: "set text event",
|
||||
},
|
||||
Marks: &pb.EventBlockSetTextMarks{Value: &model.BlockContentTextMarks{
|
||||
Marks: []*model.BlockContentTextMark{{
|
||||
Param: "https://randomsite.com/kosilica",
|
||||
Type: model.BlockContentTextMark_Link,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
@ -60,16 +75,27 @@ func TestChange(t *testing.T) {
|
|||
in.Content[0].GetBlockCreate().Blocks[0].GetText().Text,
|
||||
out.Content[0].GetBlockCreate().Blocks[0].GetText().Text,
|
||||
)
|
||||
assert.NotEqual(
|
||||
t,
|
||||
in.Content[0].GetBlockCreate().Blocks[0].GetText().Marks.Marks[0].Param,
|
||||
out.Content[0].GetBlockCreate().Blocks[0].GetText().Marks.Marks[0].Param,
|
||||
)
|
||||
assert.NotEqual(
|
||||
t,
|
||||
in.Content[1].GetBlockUpdate().Events[0].GetBlockSetText().Text,
|
||||
out.Content[1].GetBlockUpdate().Events[0].GetBlockSetText().Text,
|
||||
)
|
||||
assert.NotEqual(
|
||||
t,
|
||||
in.Content[1].GetBlockUpdate().Events[0].GetBlockSetText().Marks.Value.Marks[0].Param,
|
||||
out.Content[1].GetBlockUpdate().Events[0].GetBlockSetText().Marks.Value.Marks[0].Param,
|
||||
)
|
||||
}
|
||||
|
||||
func TestText(t *testing.T) {
|
||||
in := "Some string with ютф. Symbols? http://123.com"
|
||||
out := Text(in)
|
||||
assert.NotEqual(t, in, out)
|
||||
assert.Equal(t, text.UTF16RuneCountString(in), text.UTF16RuneCountString(out))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue