-
Notifications
You must be signed in to change notification settings - Fork 953
Expand file tree
/
Copy pathcreateLocation-test.js
More file actions
248 lines (226 loc) · 6.75 KB
/
Copy pathcreateLocation-test.js
File metadata and controls
248 lines (226 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import expect from 'expect';
import { createLocation } from 'history';
describe('createLocation', () => {
describe('with a full path', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('/the/path?the=query#the-hash')).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
});
});
});
describe('given as an object', () => {
it('has the correct properties', () => {
expect(
createLocation({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
})
).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
});
});
});
});
describe('with a relative path', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('the/path?the=query#the-hash')).toMatchObject({
pathname: 'the/path',
search: '?the=query',
hash: '#the-hash'
});
});
});
describe('given as an object', () => {
it('has the correct properties', () => {
expect(
createLocation({
pathname: 'the/path',
search: '?the=query',
hash: '#the-hash'
})
).toMatchObject({
pathname: 'the/path',
search: '?the=query',
hash: '#the-hash'
});
});
});
});
describe('with a path with no pathname', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('?the=query#the-hash')).toMatchObject({
pathname: '/',
search: '?the=query',
hash: '#the-hash'
});
});
});
describe('given as an object', () => {
it('has the correct properties', () => {
expect(
createLocation({ search: '?the=query', hash: '#the-hash' })
).toMatchObject({
pathname: '/',
search: '?the=query',
hash: '#the-hash'
});
});
});
});
describe('with a path with no search', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('/the/path#the-hash')).toMatchObject({
pathname: '/the/path',
search: '',
hash: '#the-hash'
});
});
});
describe('given as an object', () => {
it('has the correct properties', () => {
expect(
createLocation({ pathname: '/the/path', hash: '#the-hash' })
).toMatchObject({
pathname: '/the/path',
search: '',
hash: '#the-hash'
});
});
});
});
describe('with a path with no hash', () => {
describe('given as a string', () => {
it('has the correct properties', () => {
expect(createLocation('/the/path?the=query')).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: ''
});
});
});
describe('given as an object', () => {
it('has the correct properties', () => {
expect(
createLocation({ pathname: '/the/path', search: '?the=query' })
).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: ''
});
});
});
});
describe('key', () => {
it('has a key property if a key is provided', () => {
const location = createLocation('/the/path', undefined, 'key');
expect(Object.keys(location)).toContain('key');
});
it('has no key property if no key is provided', () => {
const location = createLocation('/the/path');
expect(Object.keys(location)).not.toContain('key');
});
});
describe('with embedded double-slashes (security fix for CVE-2025-68470)', () => {
describe('given as a string', () => {
it('normalizes double slashes at the start to prevent open redirect', () => {
expect(createLocation('//evil.com/path')).toMatchObject({
pathname: '/evil.com/path',
search: '',
hash: ''
});
});
it('normalizes double slashes in the middle of the path', () => {
expect(createLocation('/the//path')).toMatchObject({
pathname: '/the/path',
search: '',
hash: ''
});
});
it('normalizes multiple consecutive slashes', () => {
expect(createLocation('///the////path///segment')).toMatchObject({
pathname: '/the/path/segment',
search: '',
hash: ''
});
});
it('normalizes double slashes while preserving search and hash', () => {
expect(createLocation('//evil.com/path?query=value#hash')).toMatchObject({
pathname: '/evil.com/path',
search: '?query=value',
hash: '#hash'
});
});
it('handles protocol-relative URLs that could redirect externally', () => {
expect(createLocation('//attacker.com')).toMatchObject({
pathname: '/attacker.com',
search: '',
hash: ''
});
});
});
describe('given as an object', () => {
it('normalizes double slashes at the start to prevent open redirect', () => {
expect(
createLocation({
pathname: '//evil.com/path',
search: '?the=query',
hash: '#the-hash'
})
).toMatchObject({
pathname: '/evil.com/path',
search: '?the=query',
hash: '#the-hash'
});
});
it('normalizes double slashes in the middle of the path', () => {
expect(
createLocation({
pathname: '/the//path',
search: '?the=query',
hash: '#the-hash'
})
).toMatchObject({
pathname: '/the/path',
search: '?the=query',
hash: '#the-hash'
});
});
it('normalizes multiple consecutive slashes', () => {
expect(
createLocation({
pathname: '///the////path'
})
).toMatchObject({
pathname: '/the/path',
search: '',
hash: ''
});
});
});
describe('paths without double slashes', () => {
it('does not modify normal paths', () => {
expect(createLocation('/normal/path')).toMatchObject({
pathname: '/normal/path',
search: '',
hash: ''
});
});
it('does not modify paths with single slashes', () => {
expect(createLocation('/path/to/resource')).toMatchObject({
pathname: '/path/to/resource',
search: '',
hash: ''
});
});
});
});
});