mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
## Summary Implements the [URLPattern Web API](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) based on WebKit's implementation. URLPattern provides declarative pattern matching for URLs, similar to how regular expressions work for strings. ### Features - **Constructor**: Create patterns from strings or `URLPatternInit` dictionaries - **`test()`**: Check if a URL matches the pattern (returns boolean) - **`exec()`**: Extract matched groups from a URL (returns `URLPatternResult` or null) - **Pattern properties**: `protocol`, `username`, `password`, `hostname`, `port`, `pathname`, `search`, `hash` - **`hasRegExpGroups`**: Detect if the pattern uses custom regular expressions ### Example Usage ```js // Match URLs with a user ID parameter const pattern = new URLPattern({ pathname: '/users/:id' }); pattern.test('https://example.com/users/123'); // true pattern.test('https://example.com/posts/456'); // false const result = pattern.exec('https://example.com/users/123'); console.log(result.pathname.groups.id); // "123" // Wildcard matching const filesPattern = new URLPattern({ pathname: '/files/*' }); const match = filesPattern.exec('https://example.com/files/image.png'); console.log(match.pathname.groups[0]); // "image.png" ``` ## Implementation Notes - Adapted from WebKit's URLPattern implementation - Modified JS bindings to work with Bun's infrastructure (simpler `convertDictionary` patterns, WTF::Variant handling) - Added IsoSubspaces for proper GC integration ## Test Plan - [x] 408 tests from Web Platform Tests pass - [x] Tests fail with system Bun (URLPattern not defined), pass with debug build - [x] Manual testing of basic functionality Fixes https://github.com/oven-sh/bun/issues/2286 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
npm install
bun run ffi
bun run log
bun run gzip
bun run async
bun run sqlite
# to use custom version of bun/deno/node binary
BUN=path/to/bun bun run ffi
# or edit .env file