@@ -73,18 +73,22 @@ export function trimURL(url: string, maxLength: number): string {
7373 }
7474}
7575
76- export function encodeURIComponentPermissive ( input : string ) : string {
77- return (
78- encodeURIComponent ( input )
79- /* @ts -expect-error API supposedly not present in compilation target */
80- . replaceAll ( '%2C' , ',' )
81- . replaceAll ( '%3A' , ':' )
82- . replaceAll ( '%2F' , '/' )
83- )
76+ export function encodeURIComponentPermissive (
77+ input : string ,
78+ permittedCharacters : string
79+ ) : string {
80+ return Array . from ( permittedCharacters )
81+ . map ( ( character ) => [ encodeURIComponent ( character ) , character ] )
82+ . reduce (
83+ ( acc , [ encodedCharacter , character ] ) =>
84+ /* @ts -expect-error API supposedly not present in compilation target, but works in major browsers */
85+ acc . replaceAll ( encodedCharacter , character ) ,
86+ encodeURIComponent ( input )
87+ )
8488}
8589
8690export function encodeSearchParamEntry ( [ k , v ] : [ string , string ] ) : string {
87- return `${ encodeURIComponentPermissive ( k ) } =${ encodeURIComponentPermissive ( v ) } `
91+ return `${ encodeURIComponentPermissive ( k , ',:/' ) } =${ encodeURIComponentPermissive ( v , ',:/' ) } `
8892}
8993
9094export function isSearchEntryDefined (
@@ -114,7 +118,7 @@ export function stringifySearch(
114118 return encodedSearchEntries . length ? `?${ encodedSearchEntries . join ( '&' ) } ` : ''
115119}
116120function serializeLabelsEntry ( [ k , v ] : [ string , string ] ) {
117- return `${ encodeURIComponentPermissive ( k ) } ,${ encodeURIComponentPermissive ( v ) } `
121+ return `${ encodeURIComponentPermissive ( k , ':/' ) } ,${ encodeURIComponentPermissive ( v , ':/' ) } `
118122}
119123
120124function parseLabelsEntry ( labelString : string ) {
@@ -126,7 +130,7 @@ function serializeFilter(f: Filter) {
126130 const serializedFilter = [
127131 operator ,
128132 dimension ,
129- ...clauses . map ( ( c ) => encodeURIComponentPermissive ( c . toString ( ) ) )
133+ ...clauses . map ( ( c ) => encodeURIComponentPermissive ( c . toString ( ) , ':/' ) )
130134 ] . join ( ',' )
131135 return serializedFilter
132136}
0 commit comments