Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various edge cases in the unlocalized body calculation #1924

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nico-famedly
Copy link
Member

See the additional test cases. There are still some weird edge cases, but those are documented in the tests now.

Otherwise we were skipping the emoji tests without crypto set up and
similar, which was not intentional.
It is not clear why we ever would want to return the formatted_body when
we ask for the body, but it seems to not be used anywhere and there are
no tests covering that functionality. However it leads to suprising
results, where the plaintextBody can be tricked into returning html
without applying conversions. So we just get rid of that functionality.
Covers a few edge cases that still fail. Changes to the unlocalizedBody
function shouldn't cause behavioural changes apart from fixing a few
edge cases.
We used to randomly return an empty string when the formatted body was
empty, even though we never return an empty string usually. Similarly we
used to return the original formatted body in an edit, when the new
event has no formatted body.
Fixes some noise around logs when I was trying to enable branch
coverage.
Copy link
Member

@td-famedly td-famedly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still need to go over some of the test cases but here's my first batch of questions

lib/src/event.dart Show resolved Hide resolved
);
testUnlocalizedBody(
// not sure we actually want m.room.message here and not an empty string
expectation: 'm.room.message',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say empty string for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that is historical behaviour. At least some events don't have a body, how do you localize them? All of them just as empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localization could just use a the event type if the body is empty, inserting the type when the body is empty is very confusing imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change that, but that would be something @krille-chan signs off on, imo.

editHtml: false,
);
testUnlocalizedBody(
expectation: 'm.room.message',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also probably empty here?

testUnlocalizedBody(
expectation: 'm.room.message',
plaintextBody: false,
body: 5,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a '5' here, I thought this was already the case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? A number is not a string, so it falls back to using the same logic as if the body was missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but we could be more flexible here? I don't see why not just show the int content if we can

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that case should never happen, we want a string and it could be arbitrarily broken. The number here is just a placeholder, but in general someone could put a whole json document in there.

expectation: 'body',
plaintextBody: true,
body: 'body',
formattedBody: 5,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again would expect a '5' here

formattedBody: '<b>formatted body</b>',
html: true,
isEdit: true,
editBody: null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, would expect editBody to be shown

expectation: '**formatted body**',
plaintextBody: true,
body: 'body',
formattedBody: '<b>formatted body</b>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, would expect editBody

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit body is null, which is an invalid value, so it falls back to using the event formatted body. So you expect an empty string here? Even though the newContent is missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you expect an empty string here?

yep, falling back to the old event sounds bad

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the old event, it is the fallback body in the new event, it just usually has a weird * in front of it or so.

body: 'body',
formattedBody: '<b>formatted body</b>',
html: true,
isEdit: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

html: true,
isEdit: true,
editBody: 'edit body',
editFormattedBody: '<b>edit formatted body</b>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm shouldn't this return the edited formatted body?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because it has plaintextBody set to false.

editHtml: true,
);
testUnlocalizedBody(
expectation: 'edit body',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again would expect '5'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants