File tree Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Expand file tree Collapse file tree 2 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ public function keys(): array
99
99
return array_keys ($ this ->elements );
100
100
}
101
101
102
- public function getByKey (string $ key ): Item | InnerList | null
102
+ public function getByKey (string $ key ): Item
103
103
{
104
104
if (!array_key_exists ($ key , $ this ->elements )) {
105
105
throw InvalidOffset::dueToKeyNotFound ($ key );
@@ -141,16 +141,22 @@ public function hasIndex(int $index): bool
141
141
142
142
public function toHttpValue (): string
143
143
{
144
- $ returnValue = '' ;
144
+ $ returnValue = [] ;
145
145
146
146
foreach ($ this ->elements as $ key => $ val ) {
147
- $ returnValue .= '; ' .$ key ;
147
+ if (!$ val ->parameters ()->isEmpty ()) {
148
+ throw new SyntaxError ('the Item cannot be parameterized. ' );
149
+ }
150
+
151
+ $ value = '; ' .$ key ;
148
152
if ($ val ->value () !== true ) {
149
- $ returnValue .= '= ' .$ val ->toHttpValue ();
153
+ $ value .= '= ' .$ val ->toHttpValue ();
150
154
}
155
+
156
+ $ returnValue [] = $ value ;
151
157
}
152
158
153
- return $ returnValue ;
159
+ return implode ( '' , $ returnValue) ;
154
160
}
155
161
156
162
public function set (string $ key , Item |ByteSequence |Token |bool |int |float |string $ element ): void
Original file line number Diff line number Diff line change @@ -178,4 +178,16 @@ public function it_can_merge_without_argument_and_not_throw(): void
178
178
$ instance ->merge ();
179
179
self ::assertCount (1 , $ instance );
180
180
}
181
+
182
+ /**
183
+ * @test
184
+ */
185
+ public function it_fails_if_internal_parameters_are_changed_illegally (): void
186
+ {
187
+ $ this ->expectException (SyntaxError::class);
188
+
189
+ $ fields = Item::from ('/terms ' , ['rel ' => 'copyright ' , 'anchor ' => '#foo ' ]);
190
+ $ fields ->parameters ()->getByKey ('anchor ' )->parameters ()->set ('yolo ' , 42 );
191
+ $ fields ->toHttpValue ();
192
+ }
181
193
}
You can’t perform that action at this time.
0 commit comments