Skip to content

Commit b6be26b

Browse files
committed
Merge branch 'main' into next
2 parents 8973627 + 939576a commit b6be26b

4 files changed

Lines changed: 110 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ Breaking changes are marked with ⚠️.
88

99
## [Unreleased]
1010

11+
## [v1.8.2] - 2024-02-20
12+
13+
**Added**
14+
15+
- Test on Laravel 11 by @shuvroroy in https://github.com/tighten/ziggy/pull/709
16+
17+
**Fixed**
18+
19+
- Fix `route().current()` with encoded characters by @bakerkretzmar in https://github.com/tighten/ziggy/pull/668
20+
- Fix retrieving ziggys config from an api endpoint link in readme by @RomainMazB in https://github.com/tighten/ziggy/pull/694
21+
- Fix `route().current()` with nested/object query params by @bakerkretzmar in https://github.com/tighten/ziggy/pull/712
22+
23+
**Changed**
24+
25+
- Enable provenance for npm package by @saibotk in https://github.com/tighten/ziggy/pull/684
26+
- Handle generated file extensions more robustly by @bakerkretzmar in https://github.com/tighten/ziggy/pull/687
27+
1128
## [v1.8.1] - 2023-10-12
1229

1330
**Fixed**
@@ -316,7 +333,8 @@ Breaking changes are marked with ⚠️.
316333

317334
For previous changes see the [Releases](https://github.com/tighten/ziggy/releases) page.
318335

319-
[Unreleased]: https://github.com/tighten/ziggy/compare/v1.8.1...HEAD
336+
[Unreleased]: https://github.com/tighten/ziggy/compare/v1.8.2...HEAD
337+
[v1.8.2]: https://github.com/tighten/ziggy/compare/v1.8.1...v1.8.2
320338
[v1.8.1]: https://github.com/tighten/ziggy/compare/v1.8.0...v1.8.1
321339
[v1.8.0]: https://github.com/tighten/ziggy/compare/v1.7.0...v1.8.0
322340
[v1.7.0]: https://github.com/tighten/ziggy/compare/v1.6.2...v1.7.0

src/js/Router.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,28 @@ export default class Router extends String {
137137
)
138138
return true;
139139

140+
const isSubset = (subset, full) => {
141+
return Object.entries(subset).every(([key, value]) => {
142+
if (Array.isArray(value) && Array.isArray(full[key])) {
143+
return value.every((v) => full[key].includes(v));
144+
}
145+
146+
if (
147+
typeof value === 'object' &&
148+
typeof full[key] === 'object' &&
149+
value !== null &&
150+
full[key] !== null
151+
) {
152+
return isSubset(value, full[key]);
153+
}
154+
155+
return full[key] == value;
156+
});
157+
};
158+
140159
// Check that all passed parameters match their values in the current window URL
141160
// Use weak equality because all values in the current window URL will be strings
142-
return Object.entries(params).every(([key, value]) => routeParams[key] == value);
161+
return isSubset(params, routeParams);
143162
}
144163

145164
/**

tests/Unit/CommandRouteGeneratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ public function __toString(): string
271271

272272
class PostCommentController
273273
{
274-
public function __invoke($post, $comment) {
274+
public function __invoke($post, $comment)
275+
{
275276
//
276277
}
277278
}

tests/js/route.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,75 @@ describe('current()', () => {
12311231
expect(route().current('events.venues.show', { id: 12, user: 'Matt' })).toBe(false);
12321232
});
12331233

1234+
test('can check the current route with array and object query parameters', () => {
1235+
global.window.location.pathname = '/events/1/venues/2';
1236+
global.window.location.search =
1237+
'?filter[year]=2024&filter[month]=Jan&filter[month]=Feb&tags[0]=music&tags[1]=dance&genres[]=jazz&genres[]=folk';
1238+
1239+
expect(
1240+
route().current('events.venues.show', {
1241+
filter: {
1242+
year: '2024',
1243+
},
1244+
}),
1245+
).toBe(true);
1246+
// Weird, but technically correct since this isn't checking for an exact match, just 'overlap'
1247+
expect(
1248+
route().current('events.venues.show', {
1249+
filter: {},
1250+
}),
1251+
).toBe(true);
1252+
// Even weirder, but probably better than getting really picky about empty arrays vs. empty objects
1253+
expect(
1254+
route().current('events.venues.show', {
1255+
genres: {},
1256+
}),
1257+
).toBe(true);
1258+
expect(
1259+
route().current('events.venues.show', {
1260+
filter: {
1261+
year: '2024',
1262+
month: ['Jan'],
1263+
},
1264+
tags: ['dance', 'music'],
1265+
genres: ['folk'],
1266+
}),
1267+
).toBe(true);
1268+
1269+
expect(
1270+
route().current('events.venues.show', {
1271+
filter: {
1272+
year: '2025',
1273+
},
1274+
}),
1275+
).toBe(false);
1276+
expect(
1277+
route().current('events.venues.show', {
1278+
filter: {
1279+
year: null,
1280+
},
1281+
}),
1282+
).toBe(false);
1283+
expect(
1284+
route().current('events.venues.show', {
1285+
filter: {
1286+
year: '2024',
1287+
month: ['Mar'],
1288+
},
1289+
}),
1290+
).toBe(false);
1291+
expect(
1292+
route().current('events.venues.show', {
1293+
tags: [''],
1294+
}),
1295+
).toBe(false);
1296+
expect(
1297+
route().current('events.venues.show', {
1298+
genres: [null],
1299+
}),
1300+
).toBe(false);
1301+
});
1302+
12341303
test('can check the current route with Cyrillic characters', () => {
12351304
global.window.location.pathname = '/статистика';
12361305

0 commit comments

Comments
 (0)