|
1 | 1 | import {describe, expect, it} from 'vitest'; |
2 | | -import {getSortedMessages} from './utils.js'; |
| 2 | +import {getSortedMessages, setNestedProperty} from './utils.js'; |
3 | 3 |
|
4 | 4 | describe('getSortedMessages', () => { |
5 | 5 | it('sorts by reference path', () => { |
@@ -63,3 +63,21 @@ describe('getSortedMessages', () => { |
63 | 63 | ).toEqual(['c', 'a', 'b']); |
64 | 64 | }); |
65 | 65 | }); |
| 66 | + |
| 67 | +describe('setNestedProperty', () => { |
| 68 | + it('rejects __proto__ segments (prototype pollution)', () => { |
| 69 | + expect(() => setNestedProperty({}, '__proto__.polluted', 'x')).toThrow( |
| 70 | + 'Invalid message id segment: __proto__' |
| 71 | + ); |
| 72 | + expect( |
| 73 | + (Object.prototype as unknown as {polluted?: string}).polluted |
| 74 | + ).toBeUndefined(); |
| 75 | + }); |
| 76 | + |
| 77 | + it('creates plain data properties for nested paths', () => { |
| 78 | + const root = Object.create(null) as Record<string, unknown>; |
| 79 | + setNestedProperty(root, 'a.b', 1); |
| 80 | + expect(Object.hasOwn(root, 'a')).toBe(true); |
| 81 | + expect(({} as Record<string, unknown>).b).toBeUndefined(); |
| 82 | + }); |
| 83 | +}); |
0 commit comments