nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: tighten/ziggy
Pull request #713 (2024-02-20 23:04:47)

Remove default export from type declarations
Fixes the type declarations for v2 by making `route` a named export instead of the default.


Patch:
diff --git a/src/js/index.d.ts b/src/js/index.d.ts
index 95c4945..886bc27 100644
--- a/src/js/index.d.ts
+++ b/src/js/index.d.ts
@@ -155,16 +155,16 @@ interface Router {
  * Ziggy's route helper.
  */
 // Called with no arguments - returns a Router instance
-export default function route(): Router;
+export function route(): Router;
 // Called with a route name and optional additional arguments - returns a URL string
-export default function route<T extends RouteName>(
+export function route<T extends RouteName>(
     name: T,
     params?: RouteParams<T> | undefined,
     absolute?: boolean,
     config?: Config,
 ): string;
 // Called with configuration arguments only - returns a configured Router instance
-export default function route(
+export function route(
     name: undefined,
     params: undefined,
     absolute?: boolean,


Test patch:
diff --git a/tests/js/route.test-d.ts b/tests/js/route.test-d.ts
index 66c03d4..102c2e4 100644
--- a/tests/js/route.test-d.ts
+++ b/tests/js/route.test-d.ts
@@ -1,5 +1,5 @@
 import { assertType } from 'vitest';
-import route from '../../src/js';
+import { route } from '../../src/js';
 
 // Add generated routes to use for testing inside this file. In a real app these declarations
 // would be in a separate file generated by running `php artisan ziggy:generate --types`.
diff --git a/tests/js/route.test.js b/tests/js/route.test.js
index 85b2120..f02e175 100644
--- a/tests/js/route.test.js
+++ b/tests/js/route.test.js
@@ -1,6 +1,6 @@
 // @vitest-environment jsdom
 import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
-import { route } from '../../src/js/index.js';
+import { route } from '../../src/js';
 // import { route } from '../../dist/index.esm.js';
 // import { route } from '../../dist/index.js';
 // import route from '../../dist/route.umd.js';
Repository: tighten/ziggy
Pull request #744 (2024-04-10 16:06:03)

add ability to acess only the query params or the actual route params
Added two new methods to Router

`route().queryParams` to get only the query paramters parsed with the qs
`route().routeParams` to get only the actual route params without query params

i didn't like the routeParams name as it's no clear enough but i couldn't find another name 

this complete #742 

i didn't update the docs to inlude this but if approved will do that


Patch:
diff --git a/src/js/Router.js b/src/js/Router.js
index e05ac28..cff35c9 100644
--- a/src/js/Router.js
+++ b/src/js/Router.js
@@ -196,6 +196,14 @@ export default class Router extends String {
         return { ...params, ...query };
     }
 
+    get routeParams() {
+        return this._unresolve().params;
+    }
+
+    get queryParams() {
+        return this._unresolve().query;
+    }
+
     /**
      * Check whether the given route exists.
      *
diff --git a/src/js/index.d.ts b/src/js/index.d.ts
index 2c764ab..a8ef683 100644
--- a/src/js/index.d.ts
+++ b/src/js/index.d.ts
@@ -158,6 +158,8 @@ interface Router {
     current(): RouteName | undefined;
     current<T extends RouteName>(name: T, params?: ParameterValue | RouteParams<T>): boolean;
     get params(): Record<string, string>;
+    get routeParams(): Record<string, string>;
+    get queryParams(): Record<string, string>;
     has<T extends RouteName>(name: T): boolean;
 }
 


Test patch:
diff --git a/tests/js/route.test.js b/tests/js/route.test.js
index fd3ab2f..78b2d42 100644
--- a/tests/js/route.test.js
+++ b/tests/js/route.test.js
@@ -675,6 +675,29 @@ describe('route()', () => {
         });
     });
 
+    test('can extract only route parameters from the current URL', () => {
+        global.window.location.href = 'https://ziggy.dev/posts/1?post=2&foo=bar';
+        global.window.location.host = 'ziggy.dev';
+        global.window.location.pathname = '/posts/1';
+        global.window.location.search = '?post=2&foo=bar';
+
+        // Query param overwrites route param
+        expect(route().params).toStrictEqual({ post: '2', foo: 'bar' });
+
+        // Can't use strict equality, route().routeParams has a null prototype
+        expect(route().routeParams).toEqual({ post: '1' });
+        expect(JSON.stringify(route().routeParams)).toBe(JSON.stringify({ post: '1' }));
+    });
+
+    test('can extract only query parameters from the current URL', () => {
+        global.window.location.href = 'https://ziggy.dev/posts/1?post=2&foo=bar';
+        global.window.location.host = 'ziggy.dev';
+        global.window.location.pathname = '/posts/1';
+        global.window.location.search = '?post=2&foo=bar';
+
+        expect(route().queryParams).toStrictEqual({ post: '2', foo: 'bar' });
+    });
+
     test("can append 'extra' string/number parameter to query", () => {
         // 'posts.index' has no parameters
         expect(route('posts.index', 'extra')).toBe('https://ziggy.dev/posts?extra=');
Repository: tighten/ziggy
Pull request #766 (2024-07-22 17:05:19)

Escape special regex characters when matching routes
I noticed routes with dots inside (e.g. `{post}.{slug}`) does not match using `route().current()`. Indeed RegEx special characters are currently not escaped, so I added a remplacement for :
```
.*+^$()|[]
```
I excluded `{}?` chars because there are needed for parameters.


Patch:
diff --git a/src/js/Route.js b/src/js/Route.js
index b3b4453..eb8084c 100644
--- a/src/js/Route.js
+++ b/src/js/Route.js
@@ -80,6 +80,7 @@ export default class Route {
         // Transform the route's template into a regex that will match a hydrated URL,
         // by replacing its parameter segments with matchers for parameter values
         const pattern = this.template
+            .replace(/[.*+$()[\]]/g, '\\$&')
             .replace(/(\/?){([^}?]*)(\??)}/g, (_, slash, segment, optional) => {
                 const regex = `(?<${segment}>${
                     this.wheres[segment]?.replace(/(^\^)|(\$$)/g, '') || '[^/?]+'


Test patch:
diff --git a/tests/js/route.test.js b/tests/js/route.test.js
index 78b2d42..e530280 100644
--- a/tests/js/route.test.js
+++ b/tests/js/route.test.js
@@ -261,6 +261,10 @@ const defaultZiggy = {
             },
             parameters: ['storefront', 'catalog_uri'],
         },
+        regexSpecialChars: {
+            uri: 'test.*+$()[]/{slug}',
+            methods: ['GET', 'HEAD'],
+        },
     },
 };
 
@@ -1439,6 +1443,13 @@ describe('current()', () => {
         expect(route().current('events.venues.*')).toBe(false);
     });
 
+    test('matches route with escaped Regex special characters', () => {
+        global.window.location.pathname = '/test.*+$()[]/1';
+
+        expect(route().current()).toBe('regexSpecialChars');
+        expect(route().current('regexSpecialChars')).toBe(true);
+    });
+
     test.skip('can unresolve arbitrary urls to names and params', () => {
         const resolved = route().unresolve('https://ziggy.dev/events/1/venues?test=yes');
         expect(resolved).toStrictEqual({
Repository: tighten/ziggy
Pull request #786 (2024-11-06 11:14:06)

Fix type definition for route() with only options
The order of function definitions was disallowing `route(undefined, undefined, undefined, config)` to be matched. This PR fixes that.

I've also added a test to ensure this doesn't fail again in the future.


Patch:
diff --git a/src/js/index.d.ts b/src/js/index.d.ts
index a8ef683..7de7a63 100644
--- a/src/js/index.d.ts
+++ b/src/js/index.d.ts
@@ -168,6 +168,15 @@ interface Router {
  */
 // Called with no arguments - returns a Router instance
 export function route(): Router;
+
+// Called with configuration arguments only - returns a configured Router instance
+export function route(
+    name: undefined,
+    params: undefined,
+    absolute?: boolean,
+    config?: Config,
+): Router;
+
 // Called with a route name and optional additional arguments - returns a URL string
 export function route<T extends RouteName>(
     name: T,
@@ -175,19 +184,13 @@ export function route<T extends RouteName>(
     absolute?: boolean,
     config?: Config,
 ): string;
+
 export function route<T extends RouteName>(
     name: T,
     params?: ParameterValue | undefined,
     absolute?: boolean,
     config?: Config,
 ): string;
-// Called with configuration arguments only - returns a configured Router instance
-export function route(
-    name: undefined,
-    params: undefined,
-    absolute?: boolean,
-    config?: Config,
-): Router;
 
 /**
  * Ziggy's Vue plugin.


Test patch:
diff --git a/tests/js/route.test-d.ts b/tests/js/route.test-d.ts
index 7d6ca79..4525770 100644
--- a/tests/js/route.test-d.ts
+++ b/tests/js/route.test-d.ts
@@ -1,5 +1,5 @@
 import { assertType } from 'vitest';
-import { route } from '../../src/js';
+import { Config, route, Router } from '../../src/js';
 
 // Add generated routes to use for testing inside this file. In a real app these declarations
 // would be in a separate file generated by running `php artisan ziggy:generate --types`.
@@ -97,3 +97,8 @@ assertType(route().current('posts.comments.show', { post: 2 }));
 assertType(route().current('posts.comments.show', 2));
 // assertType(route().current('posts.comments.show', [2])); // TODO shouldn't error, only one required param
 assertType(route().current('posts.comments.show', 'foo'));
+
+// Test route function return types
+assertType<string>(route('optional', { maybe: 'foo' }));
+assertType<string>(route('optional', 'foo'));
+assertType<Router>(route(undefined, undefined, undefined, {} as Config));