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

Make ffi::Txt safer and simpler to use #60

Merged
merged 1 commit into from
Sep 11, 2024
Merged

Conversation

nyurik
Copy link
Collaborator

@nyurik nyurik commented Sep 9, 2024

Add a few helper methods to help with converting txt to str and back, which also helps with the header parsing. As a tiny addition, also simplified TestCtx instantiation.

src/vcl/utils.rs Outdated Show resolved Hide resolved
// We expect varnishd to always given us a string with a ':' in it
// If it's not the case, blow up as it might be a sign of a bigger problem.
let (key, value) = self.to_str()?.split_once(':').unwrap();
// FIXME: Consider `.trim_ascii_start()` if unicode is not a concern
Copy link
Owner

Choose a reason for hiding this comment

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

header names will be ascii, so go for it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

header name is not the issue - .trim_start uses char::is_whitespace, whereas .trim_ascii_start only removes "ascii whitespace" by using u8::is_ascii_whitespace. Which means that if a header value can have non-ascii whitespace characters in the front, they will stay there. Let's merge and decide this separate?

Add a few helper methods to help with converting txt to str and back, which also helps with the header parsing.  As a tiny addition, also simplified `TestCtx` instantiation.
@gquintard gquintard merged commit b6a9f31 into gquintard:main Sep 11, 2024
2 checks passed
@nyurik nyurik deleted the txt branch September 11, 2024 14:01
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