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(Message::appendText): QRegularExpression whitespace bug #376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tux3
Copy link

@tux3 tux3 commented Jan 17, 2025

Hello, sending a fix for a bug I ran into recently with Qt6 (https://phabricator.wikimedia.org/T383968)

It turns out that unlike QRegExp, when a QRegularExpression starts with \s, it may match whitespace including newlines.

So when looking for the start of a section, we might match "\n\n == January 2025 ==" instead of " == January 2025 =="

Then the logic that tries to skip past the header, would instead skip past the first \n, which is still before the header. Then we would think the target header is the start of the next section, and we would end up inserting a message just before the section it was intended to be appended to.

QRegularExpression is available since Qt 5.0 and is recommended. This gets rid of the old QRegExp and fixes the QRegularExpression usage in message.cpp (there's other uses of QRexExp/QRegularExpression elsewhere, but I haven't checked them for now)

Also includes some minor formatting changes. Let me know if I missed anything or if you'd like me to make some changes to the PR.

Cheers

Unlike QRegExp, when a QRegularExpression starts with \s,
it may match whitespace *including newlines*.

So when looking for the start of a section, we might match
"\n\n == January 2025 ==" instead of " == January 2025 =="

Then the logic that tries to skip past the header, would instead
skip past the first \n, which is still _before_ the header.
Then we would think the target header is the start of the next section,
and we would end up inserting a message just before the section
it was intended to be appended to.

QRegularExpression is available since Qt 5.0 and is recommended.
Let's get rid of the old QRegExp and fix the QRegularExpression usage.
@benapetr
Copy link
Member

hello, thanks for the patch.

The only question I have - did you test it? Does it work? :)

P.S. The formatting is slightly different than rest of the code ({} brackets are horizontally aligned everywhere for easy visual recognition of start and end of a block, eg. old school Microsoft visual studio style), but that's somewhat irrelevant, I am willing to merge this either way.

@tux3
Copy link
Author

tux3 commented Jan 17, 2025

The only question I have - did you test it? Does it work? :)

Yes, I've done a few manual tests and been test driving it today =)
I haven't committed a unit test, since I couldn't see a simple way to test this member function, so I've done some manual checks instead. It works with Qt5 and Qt6, and I've tried to Q&A the different edge cases manually (hopefully I didn't miss one!)

P.S. The formatting is slightly different than rest of the code ({} brackets are horizontally aligned everywhere for easy visual recognition of start and end of a block, eg. old school Microsoft visual studio style), but that's somewhat irrelevant, I am willing to merge this either way.

Ah, my bad! I searched to see which style was more prevalent and found both "} else {" and "} else\n{", so I wasn't sure. My IDE is also a big over-eager to reformat code automatically! ^^'
Will try to keep that in mind in the future =)

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