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

irc.utils, test: also remove null (\x00) in safe() #2620

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

dgw
Copy link
Member

@dgw dgw commented Sep 14, 2024

Description

Fixes #2566.

In test_irc_utils suite, rewrote test_safe and test_safe_bytes to generate a bunch more permutations of invalid characters automatically rather than writing them all out. The horse is definitely beaten far past death at this point... but the tests sure are thorough(bred).

Also renamed test_safe_null -> test_safe_none to avoid confusion; test_safe and test_safe_bytes are the cases that check behavior with null characters/bytes. Python's docs technically do refer to None as the "null object" once or twice, but most of the docs (and most of us devs) simply call it None.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make lint and make test)
    • Ran make lint myself, and tried out the test runner integration in VS Code / Gitpod. Very slick; made iterating my updated tests much easier without always tabbing back to the terminal.
  • I have tested the functionality of the things this change touches

Notes

This could go into 8.0.1, but I don't really want to mess around with hotfixes unless there's a major bug. I'm open to suggestions for improving the maintenance-branch workflow; since master is de facto for 8.1.0 dev now, the options are to keep the 8.0.x branch unprotected so I can push cherry-picks to it directly, or make @sopel-irc/rockstars review the same PR twice (once to master, once to 8.0.x) for full CI coverage. I don't love either of those.

In `test_irc_utils` suite, rewrote `test_safe` and `test_safe_bytes` to
generate a bunch more permutations of invalid characters automatically
rather than writing them all out. The horse is definitely beaten *far*
past death at this point... but the tests sure are thorough(bred).

Also renamed `test_safe_null` -> `test_safe_none` to avoid confusion;
`test_safe` and `test_safe_bytes` are the cases that check behavior with
null characters/bytes. Python's docs technically do refer to `None` as
the "null object" once or twice, but most of the docs (and most of us
devs) simply call it `None`.
@dgw dgw added the Bugfix Generally, PRs that reference (and fix) one or more issue(s) label Sep 14, 2024
@dgw dgw added this to the 8.1.0 milestone Sep 14, 2024
@dgw dgw requested a review from a team September 14, 2024 13:24
Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

Even tho I don't like when tests have too much logic in them, I draw the line at assert inside for-in bloc. I think @pytest.mark.parametrize is a much better option for these tests.

test/irc/test_irc_utils.py Outdated Show resolved Hide resolved
test/irc/test_irc_utils.py Outdated Show resolved Hide resolved
Using `pytest.mark.parametrize()` instead. Two test cases become 12.

Note: Yes, it is possible to have pytest treat each tuple generated by
`itertools.permutations()` as a single argument. Doing so yields useless
generated test-case names like `test_safe[seq0]`, though. Using three
separate test parameters of simple types (`str` or `bytes`) yields more
informative names like `test_safe[\n-\r-\x00]`.
@dgw dgw requested a review from Exirel September 15, 2024 19:33
Copy link
Contributor

@SnoopJ SnoopJ left a comment

Choose a reason for hiding this comment

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

Looks good 🐴

Is it maybe also worth mentioning in the safe() docstring that we strip NUL because it's explicitly disallowed by the spec?

@Exirel
Copy link
Contributor

Exirel commented Oct 12, 2024

Hey, this one could easily go into Sopel 8.0.1 to me. Like a hotfix of something that should be done but isn't.

@dgw
Copy link
Member Author

dgw commented Oct 13, 2024

Like a hotfix of something that should be done but isn't.

Yeah, it is, isn't it? I will tweak the safe() docstring though, as it really should mention NUL in the topline and also explain why the method exists at all.

@dgw dgw modified the milestones: 8.1.0, 8.0.1 Oct 13, 2024
Link to RFC explaining why CR, LF, and NUL are prohibited, and annotate
the version in which NUL stripping was added.
@dgw
Copy link
Member Author

dgw commented Oct 13, 2024

Netlify still does branch previews of our docs (for now… they are still stuck on Python 3.8 with no apparent plans to upgrade) but including a preview screenshot of the updated docs for this function anyway didn't seem like a bad idea.

image

Note I also fixed the \x00 references in the docstring, which needs to use \\x00 for the text to display as intended.

@dgw dgw merged commit cebfb38 into master Oct 22, 2024
17 checks passed
@dgw dgw deleted the irc.utils.safe-remove-nulls branch October 22, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Generally, PRs that reference (and fix) one or more issue(s) Documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NUL (\x00) is not filtered from IRC args/text
3 participants