Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions rs/moq-pattern/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,14 @@ impl Pattern {
/// The pattern matching `path` and every path beneath it: `path/**`.
///
/// Normalizes and validates `path` like [`literal`](Self::literal). The empty path
/// yields `**`.
/// yields `**`, and a path of [`MAX_SEGMENTS`](Self::MAX_SEGMENTS) yields the literal,
/// since nothing can sit beneath it.
pub fn subtree(path: &str) -> Result<Self, InvalidPattern> {
Self::new(literal_segments(path).chain([Segment::Globstar]))
let mut segments: Vec<Segment> = literal_segments(path).collect();
if segments.len() < Self::MAX_SEGMENTS {
segments.push(Segment::Globstar);
Comment on lines +410 to +411

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Mirror the max-depth subtree case in TypeScript

When path has exactly 32 segments, Rust now returns a literal pattern, but js/pattern/src/index.ts still appends GLOBSTAR, so its constructor rejects the resulting 33 segments. Browser callers therefore continue to fail for the same valid wire path, and the Rust and TypeScript public APIs disagree. Apply this max-depth behavior to the TypeScript twin and add the case to the shared tests/pattern.json vectors instead of covering it only in the Rust inline test.

Useful? React with 👍 / 👎.

}
Self::new(segments)
}

/// The canonical text: segments joined by `/`, wildcards as `*` and `**`.
Expand Down Expand Up @@ -993,6 +998,10 @@ mod tests {
assert_eq!(Pattern::literal("").unwrap(), Pattern::default());
assert_eq!(Pattern::subtree("foo").unwrap(), pattern("foo/**"));
assert_eq!(Pattern::subtree("/").unwrap(), Pattern::all());
let max = ["a"; Pattern::MAX_SEGMENTS].join("/");
assert_eq!(Pattern::subtree(&max).unwrap(), pattern(&max));
let deep = ["a"; Pattern::MAX_SEGMENTS + 1].join("/");
assert_eq!(Pattern::subtree(&deep), Err(InvalidPattern::TooManySegments));
assert_eq!(Pattern::literal("a/*"), Err(InvalidPattern::InvalidSegment("*".into())));
assert_eq!(Pattern::literal("**"), Err(InvalidPattern::InvalidSegment("**".into())));
}
Expand Down
Loading