Open History to see the last commit
1import { afterEach, describe, expect, it } from 'vitest'
2import {
3 decodePath,
4 deepEqual,
5 isPlainArray,
6 replaceEqualDeep,
7} from '../src/utils'
8
9describe('replaceEqualDeep', () => {
10 it('should return the same object if the input objects are equal', () => {
11 const obj = { a: 1, b: 2 }
12 const result = replaceEqualDeep(obj, obj)
13 expect(result).toBe(obj)
14 })
15
16 it('should return a new object with replaced values if the input objects are not equal', () => {
17 const obj1 = { a: 1, b: 2 }
18 const obj2 = { a: 1, b: 3 }
19 const result = replaceEqualDeep(obj1, obj2)
20 expect(result).toStrictEqual(obj2)
21 })
22
23 it('should handle arrays correctly', () => {
24 const arr1 = [1, 2, 3]
25 const arr2 = [1, 2, 4]
26 const result = replaceEqualDeep(arr1, arr2)
27 expect(result).toStrictEqual(arr2)
28 })
29
30 it('should handle nested objects correctly', () => {
31 const obj1 = { a: 1, b: { c: 2 } }
32 const obj2 = { a: 1, b: { c: 3 } }
33 const result = replaceEqualDeep(obj1, obj2)
34 expect(result).toStrictEqual(obj2)
35 })
36
37 describe('symbol properties', () => {
38 it('should look at symbol properties in the object comparison', () => {
39 const propertyKey = Symbol('property')
40 const obj1 = { a: 1, [propertyKey]: 2 }
41 const obj2 = { a: 1, [propertyKey]: 3 }
42 const result = replaceEqualDeep(obj1, obj2)
43 expect(result).toStrictEqual(obj2)
44 })
45
46 it('should copy over symbol properties when creating a new object', () => {
47 const propertyKey = Symbol('property')
48 const obj1 = { a: 1, [propertyKey]: 2 }
49 const obj2 = { a: 3, [propertyKey]: 2 }
50 const result = replaceEqualDeep(obj1, obj2)
51 expect(result).toStrictEqual(obj2)
52 })
53 })
54
55 describe('non-enumerable properties', () => {
56 it('should treat objects with non-enumerable properties as non-plain (no need for property comparisons)', () => {
57 const obj1: { a: number; b?: number } = { a: 1 }
58 Object.defineProperty(obj1, 'b', { enumerable: false, value: 2 })
59 const obj2: { a: number; b?: number } = { a: 1 }
60 Object.defineProperty(obj2, 'b', { enumerable: false, value: 3 })
61 const result = replaceEqualDeep(obj1, obj2)
62 expect(result).toBe(obj2)
63 })
64
65 it("should treat objects with non-enumerable properties as non-plain (copying doesn't happen)", () => {
66 const obj1: { a: number; b?: number } = { a: 1 }
67 Object.defineProperty(obj1, 'b', { enumerable: false, value: 2 })
68 const obj2: { a: number; b?: number } = { a: 3 }
69 Object.defineProperty(obj2, 'b', { enumerable: false, value: 2 })
70 const result = replaceEqualDeep(obj1, obj2)
71 expect(result).toBe(obj2)
72 })
73 })
74
75 it('should properly handle non-existent keys', () => {
76 const obj1 = { a: 2, c: 123 }
77 const obj2 = { a: 2, c: 123, b: undefined }
78 const result = replaceEqualDeep(obj1, obj2)
79 expect(result).toStrictEqual(obj2)
80 })
81
82 it('should correctly handle non-existent keys with the same number of fields', () => {
83 const obj1 = { a: 2, c: 123 }
84 const obj2 = { a: 2, b: undefined }
85 const result = replaceEqualDeep(obj1, obj2)
86 expect(result).toStrictEqual(obj2)
87 })
88
89 it('should return the previous value when the next value is an equal primitive', () => {
90 expect(replaceEqualDeep(1, 1)).toBe(1)
91 expect(replaceEqualDeep('1', '1')).toBe('1')
92 expect(replaceEqualDeep(true, true)).toBe(true)
93 expect(replaceEqualDeep(false, false)).toBe(false)
94 expect(replaceEqualDeep(null, null)).toBe(null)
95 expect(replaceEqualDeep(undefined, undefined)).toBe(undefined)
96 })
97 it('should return the next value when the previous value is a different value', () => {
98 const date1 = new Date()
99 const date2 = new Date()
100 expect(replaceEqualDeep(1, 0)).toBe(0)
101 expect(replaceEqualDeep(1, 2)).toBe(2)
102 expect(replaceEqualDeep('1', '2')).toBe('2')
103 expect(replaceEqualDeep(true, false)).toBe(false)
104 expect(replaceEqualDeep(false, true)).toBe(true)
105 expect(replaceEqualDeep(date1, date2)).toBe(date2)
106 })
107
108 it('should return the next value when the previous value is a different type', () => {
109 const array = [1]
110 const object = { a: 'a' }
111 expect(replaceEqualDeep(0, undefined)).toBe(undefined)
112 expect(replaceEqualDeep(undefined, 0)).toBe(0)
113 expect(replaceEqualDeep(2, undefined)).toBe(undefined)
114 expect(replaceEqualDeep(undefined, 2)).toBe(2)
115 expect(replaceEqualDeep(undefined, null)).toBe(null)
116 expect(replaceEqualDeep(null, undefined)).toBe(undefined)
117 expect(replaceEqualDeep({}, undefined)).toBe(undefined)
118 expect(replaceEqualDeep([], undefined)).toBe(undefined)
119 expect(replaceEqualDeep(array, object)).toBe(object)
120 expect(replaceEqualDeep(object, array)).toBe(array)
121 })
122
123 it('should return the previous value when the next value is an equal array', () => {
124 const prev = [1, 2]
125 const next = [1, 2]
126 expect(replaceEqualDeep(prev, next)).toBe(prev)
127 })
128
129 it('should return a copy when the previous value is a different array subset', () => {
130 const prev = [1, 2]
131 const next = [1, 2, 3]
132 const result = replaceEqualDeep(prev, next)
133 expect(result).toEqual(next)
134 expect(result).not.toBe(prev)
135 expect(result).not.toBe(next)
136 })
137
138 it('should return a copy when the previous value is a different array superset', () => {
139 const prev = [1, 2, 3]
140 const next = [1, 2]
141 const result = replaceEqualDeep(prev, next)
142 expect(result).toEqual(next)
143 expect(result).not.toBe(prev)
144 expect(result).not.toBe(next)
145 })
146
147 it('should return the previous value when the next value is an equal empty array', () => {
148 const prev: Array<any> = []
149 const next: Array<any> = []
150 expect(replaceEqualDeep(prev, next)).toBe(prev)
151 })
152
153 it('should return the previous value when the next value is an equal empty object', () => {
154 const prev = {}
155 const next = {}
156 expect(replaceEqualDeep(prev, next)).toBe(prev)
157 })
158
159 it('should return the previous value when the next value is an equal object', () => {
160 const prev = { a: 'a' }
161 const next = { a: 'a' }
162 expect(replaceEqualDeep(prev, next)).toBe(prev)
163 })
164
165 it('should replace different values in objects', () => {
166 const prev = { a: { b: 'b' }, c: 'c' }
167 const next = { a: { b: 'b' }, c: 'd' }
168 const result = replaceEqualDeep(prev, next)
169 expect(result).toEqual(next)
170 expect(result).not.toBe(prev)
171 expect(result).not.toBe(next)
172 expect(result.a).toBe(prev.a)
173 expect(result.c).toBe(next.c)
174 })
175
176 it('should replace different values in arrays', () => {
177 const prev = [1, { a: 'a' }, { b: { b: 'b' } }, [1]] as const
178 const next = [1, { a: 'a' }, { b: { b: 'c' } }, [1]] as const
179 const result = replaceEqualDeep(prev, next)
180 expect(result).toEqual(next)
181 expect(result).not.toBe(prev)
182 expect(result).not.toBe(next)
183 expect(result[0]).toBe(prev[0])
184 expect(result[1]).toBe(prev[1])
185 expect(result[2]).not.toBe(next[2])
186 expect(result[2].b.b).toBe(next[2].b.b)
187 expect(result[3]).toBe(prev[3])
188 })
189
190 it('should replace different values in arrays when the next value is a subset', () => {
191 const prev = [{ a: 'a' }, { b: 'b' }, { c: 'c' }]
192 const next = [{ a: 'a' }, { b: 'b' }]
193 const result = replaceEqualDeep(prev, next)
194 expect(result).toEqual(next)
195 expect(result).not.toBe(prev)
196 expect(result).not.toBe(next)
197 expect(result[0]).toBe(prev[0])
198 expect(result[1]).toBe(prev[1])
199 expect(result[2]).toBeUndefined()
200 })
201
202 it('should replace different values in arrays when the next value is a superset', () => {
203 const prev = [{ a: 'a' }, { b: 'b' }]
204 const next = [{ a: 'a' }, { b: 'b' }, { c: 'c' }]
205 const result = replaceEqualDeep(prev, next)
206 expect(result).toEqual(next)
207 expect(result).not.toBe(prev)
208 expect(result).not.toBe(next)
209 expect(result[0]).toBe(prev[0])
210 expect(result[1]).toBe(prev[1])
211 expect(result[2]).toBe(next[2])
212 })
213
214 it('should copy objects which are not arrays or objects', () => {
215 const prev = [{ a: 'a' }, { b: 'b' }, { c: 'c' }, 1]
216 const next = [{ a: 'a' }, new Map(), { c: 'c' }, 2]
217 const result = replaceEqualDeep(prev, next)
218 expect(result).not.toBe(prev)
219 expect(result).not.toBe(next)
220 expect(result[0]).toBe(prev[0])
221 expect(result[1]).toBe(next[1])
222 expect(result[2]).toBe(prev[2])
223 expect(result[3]).toBe(next[3])
224 })
225
226 it('should support equal objects which are not arrays or objects', () => {
227 const map = new Map()
228 const prev = [map, [1]]
229 const next = [map, [1]]
230 const result = replaceEqualDeep(prev, next)
231 expect(result).toBe(prev)
232 })
233
234 it('should support non equal objects which are not arrays or objects', () => {
235 const map1 = new Map()
236 const map2 = new Map()
237 const prev = [map1, [1]]
238 const next = [map2, [1]]
239 const result = replaceEqualDeep(prev, next)
240 expect(result).not.toBe(prev)
241 expect(result).not.toBe(next)
242 expect(result[0]).toBe(next[0])
243 expect(result[1]).toBe(prev[1])
244 })
245
246 it('should support objects which are not plain arrays', () => {
247 const prev = Object.assign([1, 2], { a: { b: 'b' }, c: 'c' })
248 const next = Object.assign([1, 2], { a: { b: 'b' }, c: 'c' })
249 const result = replaceEqualDeep(prev, next)
250 expect(result).toBe(next)
251 })
252
253 it('should replace all parent objects if some nested value changes', () => {
254 const prev = {
255 todo: { id: '1', meta: { createdAt: 0 }, state: { done: false } },
256 otherTodo: { id: '2', meta: { createdAt: 0 }, state: { done: true } },
257 }
258 const next = {
259 todo: { id: '1', meta: { createdAt: 0 }, state: { done: true } },
260 otherTodo: { id: '2', meta: { createdAt: 0 }, state: { done: true } },
261 }
262 const result = replaceEqualDeep(prev, next)
263 expect(result).toEqual(next)
264 expect(result).not.toBe(prev)
265 expect(result).not.toBe(next)
266 expect(result.todo).not.toBe(prev.todo)
267 expect(result.todo).not.toBe(next.todo)
268 expect(result.todo.id).toBe(next.todo.id)
269 expect(result.todo.meta).toBe(prev.todo.meta)
270 expect(result.todo.state).not.toBe(next.todo.state)
271 expect(result.todo.state.done).toBe(next.todo.state.done)
272 expect(result.otherTodo).toBe(prev.otherTodo)
273 })
274
275 it('should replace all parent arrays if some nested value changes', () => {
276 const prev = {
277 todos: [
278 { id: '1', meta: { createdAt: 0 }, state: { done: false } },
279 { id: '2', meta: { createdAt: 0 }, state: { done: true } },
280 ],
281 }
282 const next = {
283 todos: [
284 { id: '1', meta: { createdAt: 0 }, state: { done: true } },
285 { id: '2', meta: { createdAt: 0 }, state: { done: true } },
286 ],
287 }
288 const result = replaceEqualDeep(prev, next)
289 expect(result).toEqual(next)
290 expect(result).not.toBe(prev)
291 expect(result).not.toBe(next)
292 expect(result.todos).not.toBe(prev.todos)
293 expect(result.todos).not.toBe(next.todos)
294 expect(result.todos[0]).not.toBe(prev.todos[0])
295 expect(result.todos[0]).not.toBe(next.todos[0])
296 expect(result.todos[0]?.id).toBe(next.todos[0]?.id)
297 expect(result.todos[0]?.meta).toBe(prev.todos[0]?.meta)
298 expect(result.todos[0]?.state).not.toBe(next.todos[0]?.state)
299 expect(result.todos[0]?.state.done).toBe(next.todos[0]?.state.done)
300 expect(result.todos[1]).toBe(prev.todos[1])
301 })
302
303 it('should be able to share values that contain undefined', () => {
304 const current = [
305 {
306 data: undefined,
307 foo: true,
308 },
309 ]
310
311 const next = replaceEqualDeep(current, [
312 {
313 data: undefined,
314 foo: true,
315 },
316 ])
317
318 expect(current).toBe(next)
319 })
320
321 it('should return the previous value when both values are an array of undefined', () => {
322 const current = [undefined]
323 const next = replaceEqualDeep(current, [undefined])
324
325 expect(next).toBe(current)
326 })
327
328 it('should return the previous value when both values are an array that contains undefined', () => {
329 const current = [{ foo: 1 }, undefined]
330 const next = replaceEqualDeep(current, [{ foo: 1 }, undefined])
331
332 expect(next).toBe(current)
333 })
334
335 it('works w/ null prototype objects', () => {
336 const current = Object.create(null)
337 const next = Object.create(null)
338
339 current.foo = 'bar'
340 next.foo = 'bar'
341 expect(replaceEqualDeep(current, next)).toBe(current)
342
343 next.foo = 'baz'
344 expect(replaceEqualDeep(current, next)).toEqual(next)
345 })
346})
347
348describe('isPlainArray', () => {
349 it('should return `true` for plain arrays', () => {
350 expect(isPlainArray([1, 2])).toEqual(true)
351 })
352
353 it('should return `false` for non plain arrays', () => {
354 expect(isPlainArray(Object.assign([1, 2], { a: 'b' }))).toEqual(false)
355 })
356})
357
358describe('deepEqual', () => {
359 describe.each([false, true])('partial = %s', (partial) => {
360 it('should return `true` for equal objects', () => {
361 const a = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
362 const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
363 expect(deepEqual(a, b, { partial })).toEqual(true)
364 expect(deepEqual(b, a, { partial })).toEqual(true)
365 })
366
367 it('should return `false` for non equal objects', () => {
368 const a = { a: { b: 'b' }, c: 'c' }
369 const b = { a: { b: 'c' }, c: 'c' }
370 expect(deepEqual(a, b, { partial })).toEqual(false)
371 expect(deepEqual(b, a, { partial })).toEqual(false)
372 })
373
374 it('should return `true` for equal objects and ignore `undefined` properties', () => {
375 const a = { a: 'a', b: undefined, c: 'c' }
376 const b = { a: 'a', c: 'c' }
377 expect(deepEqual(a, b, { partial })).toEqual(true)
378 expect(deepEqual(b, a, { partial })).toEqual(true)
379 })
380
381 it('should return `true` for equal objects and ignore `undefined` nested properties', () => {
382 const a = { a: { b: 'b', x: undefined }, c: 'c' }
383 const b = { a: { b: 'b' }, c: 'c', d: undefined }
384 expect(deepEqual(a, b, { partial })).toEqual(true)
385 expect(deepEqual(b, a, { partial })).toEqual(true)
386 })
387
388 it('should return `true` for equal arrays and ignore `undefined` object properties', () => {
389 const a = { a: { b: 'b' }, c: undefined }
390 const b = { a: { b: 'b' } }
391 expect(deepEqual([a], [b], { partial })).toEqual(true)
392 expect(deepEqual([b], [a], { partial })).toEqual(true)
393 })
394
395 it('should return `true` for equal arrays and ignore nested `undefined` object properties', () => {
396 const a = { a: { b: 'b', x: undefined }, c: 'c' }
397 const b = { a: { b: 'b' }, c: 'c' }
398 expect(deepEqual([a], [b], { partial })).toEqual(true)
399 expect(deepEqual([b], [a], { partial })).toEqual(true)
400 })
401 })
402
403 describe('ignoreUndefined = false', () => {
404 const ignoreUndefined = false
405 describe('partial = false', () => {
406 const partial = false
407 it('should return `false` for objects', () => {
408 const a = { a: { b: 'b', x: undefined }, c: 'c' }
409 const b = { a: { b: 'b' }, c: 'c', d: undefined }
410 expect(deepEqual(a, b, { partial, ignoreUndefined })).toEqual(false)
411 expect(deepEqual(b, a, { partial, ignoreUndefined })).toEqual(false)
412 })
413
414 it('should return `false` for arrays', () => {
415 const a = { a: { b: 'b', x: undefined }, c: 'c' }
416 const b = { a: { b: 'b' }, c: 'c' }
417 expect(deepEqual([a], [b], { partial, ignoreUndefined })).toEqual(false)
418 expect(deepEqual([b], [a], { partial, ignoreUndefined })).toEqual(false)
419 })
420 })
421 describe('partial = true', () => {
422 const partial = true
423 it('should return `true` for objects', () => {
424 const a = { a: { b: 'b' }, c: 'c' }
425 const b = { a: { b: 'b' }, c: 'c', d: undefined }
426 expect(deepEqual(a, b, { partial, ignoreUndefined })).toEqual(true)
427 expect(deepEqual(b, a, { partial, ignoreUndefined })).toEqual(true)
428 })
429
430 it('should return `true` for arrays', () => {
431 const a = { a: { b: 'b', x: undefined }, c: 'c' }
432 const b = { a: { b: 'b' }, c: 'c' }
433 expect(deepEqual([a], [b], { partial, ignoreUndefined })).toEqual(true)
434 expect(deepEqual([b], [a], { partial, ignoreUndefined })).toEqual(true)
435 })
436 })
437 })
438
439 describe('partial comparison', () => {
440 it('correctly compares partially equal objects', () => {
441 const a = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
442 const b = { a: { b: 'b' }, c: 'c' }
443 expect(deepEqual(a, b, { partial: true })).toEqual(true)
444 expect(deepEqual(b, a, { partial: true })).toEqual(false)
445 })
446
447 it('correctly compares partially equal objects and ignores `undefined` object properties', () => {
448 const a = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }], e: undefined }
449 const b = { a: { b: 'b' }, c: 'c', d: undefined }
450 expect(deepEqual(a, b, { partial: true })).toEqual(true)
451 expect(deepEqual(b, a, { partial: true })).toEqual(false)
452 })
453 })
454
455 // This might not be what we want, but this test documents how things are now
456 describe('symbol and non-enumerable properties are not handled', () => {
457 it.fails(
458 'should return `false` for unequal objects with symbol properties',
459 () => {
460 const key = Symbol('foo')
461 const a = { [key]: 1 }
462 const b = { [key]: 2 }
463 expect(deepEqual(a, b)).toEqual(false)
464 },
465 )
466
467 it.fails(
468 'should return `false` for unequal objects with non-enumerable properties',
469 () => {
470 const a = {}
471 Object.defineProperty(a, 'prop', { value: 1, enumerable: false })
472 const b = {}
473 Object.defineProperty(b, 'prop', { value: 2, enumerable: false })
474 expect(deepEqual(a, b)).toEqual(false)
475 },
476 )
477 })
478
479 // We voluntarily fail in this case, because users should not do it, and ignoring it enables some performance improvements
480 describe('augmented object prototype fail case (no one should do this anyway)', () => {
481 it.fails(
482 'should not compare objects with augmented prototype properties',
483 () => {
484 // @ts-expect-error -- typescript is right to complain here, don't do this!
485 Object.prototype.x = 'x'
486 const a = { a: 1 }
487 const b = { a: 1 }
488 expect(deepEqual(a, b, { ignoreUndefined: false })).toEqual(true)
489 },
490 )
491
492 afterEach(() => {
493 // it's probably not necessary to clean this up because vitest isolates tests
494 // but just in case isolation ever gets disabled, we clean the prototype to avoid disturbing other tests
495 // @ts-expect-error
496 delete Object.prototype.x
497 })
498 })
499})
500
501describe('decodePath', () => {
502 it('should decode a path segment with no ignored items existing', () => {
503 const itemsToCheck = ['%25', '%5C']
504 const stringToCheck =
505 'https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'
506 const expectedResult = 'https://mozilla.org/?x=шеллы'
507
508 const result = decodePath(stringToCheck, itemsToCheck)
509
510 expect(result).toBe(expectedResult)
511 })
512
513 it('should decode a path segment with one ignored character and one ignored item existing', () => {
514 const itemsToCheck = ['%25']
515 const stringToCheck =
516 'https://mozilla.org/?x=%25%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
517 const expectedResult = 'https://mozilla.org/?x=%25ше\\ллы'
518
519 const result = decodePath(stringToCheck, itemsToCheck)
520
521 expect(result).toBe(expectedResult)
522 })
523
524 it('should decode a path segment with multiple ignored characters and first ignored item existing', () => {
525 const itemsToCheck = ['%25', '%5C']
526 let stringToCheck =
527 'https://mozilla.org/?x=%25%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'
528 let expectedResult = 'https://mozilla.org/?x=%25шеллы'
529
530 let result = decodePath(stringToCheck, itemsToCheck)
531
532 expect(result).toBe(expectedResult)
533
534 stringToCheck = 'https://mozilla.org/?x=%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
535 expectedResult = 'https://mozilla.org/?x=ше%5Cллы'
536
537 result = decodePath(stringToCheck, itemsToCheck)
538
539 expect(result).toBe(expectedResult)
540 })
541
542 it('should decode a path segment with multiple ignored characters and other ignored item existing', () => {
543 const itemsToCheck = ['%25', '%5C']
544 let stringToCheck =
545 'https://mozilla.org/?x=%5C%D1%88%D0%B5%D0%BB%D0%BB%D1%8B'
546 let expectedResult = 'https://mozilla.org/?x=%5Cшеллы'
547
548 let result = decodePath(stringToCheck, itemsToCheck)
549
550 expect(result).toBe(expectedResult)
551
552 stringToCheck = 'https://mozilla.org/?x=%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
553 expectedResult = 'https://mozilla.org/?x=ше%5Cллы'
554
555 result = decodePath(stringToCheck, itemsToCheck)
556
557 expect(result).toBe(expectedResult)
558 })
559
560 it('should decode a path segment with multiple ignored characters and multiple ignored items existing', () => {
561 const itemsToCheck = ['%25', '%5C']
562 const stringToCheck =
563 'https://mozilla.org/?x=%25%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B'
564 const expectedResult = 'https://mozilla.org/?x=%25ше%5Cллы'
565
566 const result = decodePath(stringToCheck, itemsToCheck)
567
568 expect(result).toBe(expectedResult)
569 })
570
571 it('should decode a path segment, ignoring `%` and `\\` by default, with multiple ignored items existing', () => {
572 const stringToCheck =
573 'https://mozilla.org/?x=%25%D1%88%D0%B5%5C%D0%BB%D0%BB%D1%8B%2F'
574 const expectedResult = 'https://mozilla.org/?x=%25ше%5Cллы%2F'
575
576 const result = decodePath(stringToCheck)
577
578 expect(result).toBe(expectedResult)
579 })
580
581 it('should handle malformed percent-encodings gracefully', () => {
582 const stringToCheck = 'path%ZZ%D1%88test%5C%C3%A9'
583 // Malformed sequences should remain as-is, valid ones decoded
584 const result = decodePath(stringToCheck)
585 expect(result).toBe(`path%ZZ%D1%88test%5Cé`)
586 })
587
588 it('should return empty string unchanged', () => {
589 expect(decodePath('')).toBe('')
590 })
591
592 it('should return strings without encoding unchanged', () => {
593 const stringToCheck = 'plain-text-path'
594 expect(decodePath(stringToCheck)).toBe(stringToCheck)
595 })
596
597 it('should handle consecutive ignored characters', () => {
598 const stringToCheck = 'test%25%25end'
599 const expectedResult = 'test%25%25end'
600 expect(decodePath(stringToCheck)).toBe(expectedResult)
601 })
602
603 it('should handle multiple ignored items of the same type with varying case', () => {
604 const stringToCheck = '/params-ps/named/foo%2Fabc/c%2Fh'
605 const expectedResult = '/params-ps/named/foo%2Fabc/c%2Fh'
606 expect(decodePath(stringToCheck)).toBe(expectedResult)
607
608 const stringToCheckWithLowerCase = '/params-ps/named/foo%2Fabc/c%5C%2f%5cAh'
609 const expectedResultWithLowerCase =
610 '/params-ps/named/foo%2Fabc/c%5C%2F%5CAh'
611 expect(decodePath(stringToCheckWithLowerCase)).toBe(
612 expectedResultWithLowerCase,
613 )
614 })
615})