Skip to content

RUST-2354 Add option for max length when parsing cstrings#643

Open
isabelatkinson wants to merge 3 commits intomongodb:mainfrom
isabelatkinson:max-cstr-len
Open

RUST-2354 Add option for max length when parsing cstrings#643
isabelatkinson wants to merge 3 commits intomongodb:mainfrom
isabelatkinson:max-cstr-len

Conversation

@isabelatkinson
Copy link
Contributor

@isabelatkinson isabelatkinson commented Feb 19, 2026

The maximum length can be configured on an iterator or through new getter methods:

// document
let key = cstr!("aaaaa");
let doc = rawdoc! { key: "b" };
let iter = doc.iter().max_cstr_parse_len(key.len());
let b = doc.get_with_max_cstr_parse_len(key, key.len());

// array
let array = doc.get_array("array").unwrap();
let iter = array.into_iter().max_cstr_parse_len(5);
let val = array.get_with_max_cstr_parse_len(2, 5);

The API additions are exposed behind an sfp-internal feature flag. The documentation for them is hidden. This will give us more semver flexibility to make breaking changes if needed. Docs for the new features can be generated locally by running:

RUSTDOCFLAGS='-Z unstable-options --document-hidden-items' cargo +nightly doc --all-features --open

@isabelatkinson isabelatkinson marked this pull request as ready for review February 19, 2026 20:12
@isabelatkinson isabelatkinson requested a review from a team as a code owner February 19, 2026 20:12
@isabelatkinson isabelatkinson requested review from abr-egn, jyemin and kevinAlbs and removed request for abr-egn February 19, 2026 20:12
Copy link
Collaborator

@kevinAlbs kevinAlbs 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 with a suggestion to validate regex.

/// encountered that exceeds the provided `len`.
#[cfg(feature = "sfp-internal")]
#[doc(hidden)]
pub fn get_with_max_cstr_parse_len(
Copy link
Contributor

Choose a reason for hiding this comment

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

(not needed for this PR since this is an internal API we can change if needed)

If we end up wanting to add any more control over parsing we might want to change this to get_with_options and make a proper options struct.

@patrickfreed
Copy link
Contributor

Going to give this a quick try in monguard tomorrow to confirm we're not missing any requirements, but the interface LGTM after a quick look.

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.

5 participants