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 regex skipping over all src except the last #3021

Merged
merged 2 commits into from Feb 24, 2024
Merged

Conversation

vaxr
Copy link
Contributor

@vaxr vaxr commented Feb 23, 2024

See #2918

Adapting HTML_MEDIA_TAGS to allow for > inside '' and "" led to multiple images inside a field sometimes being disregarded and marked as "unused". This seems to have been caused by a missing lazy (?) quantifier for the regex part skipping over non->.

@meliache Thanks for finding this! If you can, please check if this resolves the bug from your end.

Adapting HTML_MEDIA_TAGS to allow for `>` inside '' and "" led to
multiple images inside a field sometimes being disregarded and
marked as "unused". This seems to have been caused by a missing
lazy (?) quantifier for the regex part skipping over non-`>`.
@vaxr
Copy link
Contributor Author

vaxr commented Feb 23, 2024

Not sure why the build failed. Seems to be unrelated? Tests pass locally.

let seen = normalize_and_maybe_rename_files_helper(&mut checker, field);
assert!(seen.contains("foo-sd.jpg"));
assert!(seen.contains("bar-sd.jpg"));

Copy link
Contributor

@meliache meliache Feb 23, 2024

Choose a reason for hiding this comment

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

Would it make sense to add some tests for where there's whitespace, a newline or text (including other html tags) between the image tags? Also maybe tests for when there are more than two images?

For the particular bug that this PR fixes all that makes no difference. But in my mind, the tests should cover more than the bug that we just fixed, but also unforeseen future bugs. On the other hand that would add a lot of boilerplate code. I'm haven't done much Anki development, so not sure what the testing guidelines here are...

Copy link
Contributor Author

@vaxr vaxr Feb 23, 2024

Choose a reason for hiding this comment

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

For the issue at hand, the tests added are the minimum retention test addressing this particular fix. There are three because the bug only showed up on subsequent usage of single or double quotes. That's all a retention test should do as far as I'm concerned.

I agree it would be great to have more tests in general. How detailed the tests should be is a matter of debate I suppose. Surely there are lower hanging fruits.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining, that's fine with me.

@meliache
Copy link
Contributor

please check if this resolves the bug from your end.

Compiling finished, I can't reproduce the bug on this PR, thanks 👍

@dae
Copy link
Member

dae commented Feb 24, 2024

Thank you @meliache for spotting the problem, and thank you @vaxr for the quick fix, complete with tests!

@dae dae merged commit 68b374e into ankitects:main Feb 24, 2024
1 check passed
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.

None yet

3 participants