File tree Expand file tree Collapse file tree 4 files changed +11
-7
lines changed Expand file tree Collapse file tree 4 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 7
7
use Stringable ;
8
8
9
9
use Throwable ;
10
+
10
11
use function base64_decode ;
11
12
use function base64_encode ;
12
13
use function preg_match ;
Original file line number Diff line number Diff line change 5
5
namespace Bakame \Http \StructuredFields ;
6
6
7
7
use DateTimeInterface ;
8
- use Throwable ;
9
8
10
9
/**
11
10
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-3.3
@@ -49,10 +48,10 @@ public static function tryFromValue(mixed $value): self|null
49
48
is_float ($ value ) => Type::Decimal,
50
49
is_bool ($ value ) => Type::Boolean,
51
50
is_string ($ value ) => match (true ) {
52
- 1 === preg_match ('/[^\x20-\x7f]/ ' , $ value ) => Type::DisplayString,
53
- 1 === preg_match ("/^([a-z*][a-z\d:\/!# \$%&'*+\-.^_`|~]*)$/i " , $ value ) => Type::Token,
54
- null !== ByteSequence::tryFromEncoded ($ value ) => Type::ByteSequence,
55
- default => Type::String,
51
+ 1 === preg_match ('/[^\x20-\x7f]/ ' , $ value ) => Type::DisplayString,
52
+ 1 === preg_match ("/^([a-z*][a-z\d:\/!# \$%&'*+\-.^_`|~]*)$/i " , $ value ) => Type::Token,
53
+ null !== ByteSequence::tryFromEncoded ($ value ) => Type::ByteSequence,
54
+ default => Type::String,
56
55
},
57
56
default => null ,
58
57
};
Original file line number Diff line number Diff line change @@ -274,7 +274,7 @@ public static function itemTypeProvider(): iterable
274
274
],
275
275
'string ' => [
276
276
'item ' => Item::new ('42 ' ),
277
- 'expectedType ' => Type::String ,
277
+ 'expectedType ' => Type::ByteSequence ,
278
278
],
279
279
'token ' => [
280
280
'item ' => Item::new (Token::fromString ('forty-two ' )),
Original file line number Diff line number Diff line change @@ -57,8 +57,12 @@ public static function itemTypeProvider(): iterable
57
57
'value ' => 42.0 ,
58
58
'expectedType ' => Type::Decimal,
59
59
],
60
- 'string ' => [
60
+ 'string as a Bytesequence ' => [
61
61
'value ' => '42 ' ,
62
+ 'expectedType ' => Type::ByteSequence,
63
+ ],
64
+ 'string as a String ' => [
65
+ 'value ' => 'Hello Boy! ' ,
62
66
'expectedType ' => Type::String,
63
67
],
64
68
'token ' => [
You can’t perform that action at this time.
0 commit comments