File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 991010 * @license https://github.com/opencodeco/hyperf-metric/blob/main/LICENSE
1111 */
12+
1213namespace Hyperf \Metric \Support ;
1314
1415final class Uri
@@ -17,13 +18,15 @@ public static function sanitize(string $uri): string
1718 {
1819 return preg_replace (
1920 [
21+ '/\/(?<=\/)[ED]\d{8}\d{12}[0-9a-zA-Z]{11}(?=\/)?/ ' ,
2022 '/\/(?<=\/)[a-f0-9]{40}(?=\/)?/i ' ,
2123 '/\/(?<=\/)([A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12})(?=\/)?/i ' ,
2224 '/\/(?<=\/)([A-Z]{3}-?\d[0-9A-Z]\d{2})(?=\/)?/i ' ,
2325 '/\/(?<=\/)[0-9A-F]{16,24}(?=\/)?/i ' ,
2426 '/\/(?<=\/)\d+(?=\/)?/ ' ,
2527 ],
2628 [
29+ '/<E2E-ID> ' ,
2730 '/<SHA1> ' ,
2831 '/<UUID> ' ,
2932 '/<LICENSE-PLATE> ' ,
@@ -33,4 +36,4 @@ public static function sanitize(string $uri): string
3336 '/ ' . ltrim ($ uri , '/ ' ),
3437 );
3538 }
36- }
39+ }
Original file line number Diff line number Diff line change @@ -118,4 +118,18 @@ public function testSanitizeHashsStrings(): void
118118 self ::assertSame ('/v8/test/<SHA1>/<SHA1>/<SHA1>/ ' , Uri::sanitize ('/v8/test/141da78905dcaa7ed8d4da7c3f49a2415ebdc110/141da78905dcaa7ed8d4da7c3f49a2415ebdc110/141da78905dcaa7ed8d4da7c3f49a2415ebdc110/ ' ));
119119 self ::assertSame ('/v8/test/<SHA1>/<SHA1>/<SHA1>/ ' , Uri::sanitize ('/v8/test/7110EDA4D09E062AA5E4A390B0A572AC0D2C0220/7110EDA4D09E062AA5E4A390B0A572AC0D2C0220/7110EDA4D09E062AA5E4A390B0A572AC0D2C0220/ ' ));
120120 }
121+
122+ public function testSanitizeEndToEndId (): void
123+ {
124+ $ e2eid = 'E99999999202401010000abcDEF12345 ' ;
125+
126+ self ::assertSame ('/v1/test ' , Uri::sanitize ('/v1/test ' ));
127+ self ::assertSame ('/v2/test/<E2E-ID> ' , Uri::sanitize ("/v2/test/ {$ e2eid }" ));
128+ self ::assertSame ('/v3/test/<E2E-ID>/bar ' , Uri::sanitize ("/v3/test/ {$ e2eid }/bar " ));
129+ self ::assertSame ('/v4/test/<E2E-ID>/bar/<E2E-ID>/ ' , Uri::sanitize ("/v4/test/ {$ e2eid }/bar/ {$ e2eid }/ " ));
130+ self ::assertSame ('/v5/test/<E2E-ID>/<E2E-ID> ' , Uri::sanitize ("/v5/test/ {$ e2eid }/ {$ e2eid }" ));
131+ self ::assertSame ('/v6/test/<E2E-ID>/<E2E-ID>/ ' , Uri::sanitize ("/v6/test/ {$ e2eid }/ {$ e2eid }/ " ));
132+ self ::assertSame ('/v7/test/<E2E-ID>/<E2E-ID>/<E2E-ID> ' , Uri::sanitize ("/v7/test/ {$ e2eid }/ {$ e2eid }/ {$ e2eid }" ));
133+ self ::assertSame ('/v8/test/<E2E-ID>/<E2E-ID>/<E2E-ID>/ ' , Uri::sanitize ("/v8/test/ {$ e2eid }/ {$ e2eid }/ {$ e2eid }/ " ));
134+ }
121135}
You can’t perform that action at this time.
0 commit comments