File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,9 @@ public function isString(): bool
34
34
public function getStringPrefix (): string
35
35
{
36
36
$ str = $ this ->value ;
37
+ if (strlen ($ str ) < 2 ) {
38
+ return '' ;
39
+ }
37
40
return $ str [0 ] . $ str [1 ];
38
41
}
39
42
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ class JsonString
7
7
// encodeStr
8
8
public static function encodeString (string $ str ): string
9
9
{
10
+ if (strlen ($ str ) < 2 ) {
11
+ return $ str ;
12
+ }
10
13
$ prefix = $ str [0 ] . $ str [1 ];
11
14
switch ($ prefix ) {
12
15
case 'b| ' :
@@ -22,6 +25,9 @@ public static function encodeString(string $str): string
22
25
// decodeStr
23
26
public static function decodeString (string $ str ): string
24
27
{
28
+ if (strlen ($ str ) < 2 ) {
29
+ return $ str ;
30
+ }
25
31
$ prefix = $ str [0 ] . $ str [1 ];
26
32
return $ prefix === 's| ' ? substr ($ str , 2 ) : $ str ;
27
33
}
Original file line number Diff line number Diff line change @@ -100,4 +100,21 @@ public function testNestedWithSameKey()
100
100
// Assert
101
101
$ this ->assertEquals ($ data , $ decompressed );
102
102
}
103
+
104
+ public function testShortString ()
105
+ {
106
+ $ data = [
107
+ '' ,
108
+ 'p ' ,
109
+ 'pp '
110
+ ];
111
+ $ compressed = Compressor::create ()
112
+ ->compress ($ data );
113
+ $ compressedJson = $ compressed
114
+ ->toJson ();
115
+ $ decompressed = Compressor::create ()
116
+ ->decompressJson ($ compressedJson );
117
+ // Assert
118
+ $ this ->assertEquals ($ data , $ decompressed );
119
+ }
103
120
}
You can’t perform that action at this time.
0 commit comments