@@ -703,18 +703,40 @@ export const isRHAdvisory = (name) => /^(RHEA|RHBA|RHSA)/.test(name);
703703export const buildTagString = ( tag ) =>
704704 `${ tag . category } /${ tag . values ?. tagKey } =${ tag . value ?. tagValue } ` ;
705705
706+ /**
707+ * Build one `tags=…` query fragment with a single URI encode pass. Inventory / insights-chrome
708+ * sometimes passes tag strings that are already `tags=` segments or percent-encoded and encoding
709+ * again turns `%2F` into `%252F` and breaks the patch API.
710+ */
711+ const buildTagsQuerySegment = ( rawTagInput ) => {
712+ if ( rawTagInput === undefined || rawTagInput === null ) {
713+ return '' ;
714+ }
715+ let inner = String ( rawTagInput ) . trim ( ) ;
716+ if ( inner . startsWith ( 'tags=' ) ) {
717+ inner = inner . slice ( 5 ) ;
718+ }
719+ let decoded = inner ;
720+ try {
721+ decoded = decodeURIComponent ( inner ) ;
722+ } catch {
723+ decoded = inner ;
724+ }
725+ return `tags=${ encodeURIComponent ( decoded ) } ` ;
726+ } ;
727+
706728export const mapGlobalFilters = ( tags , workloads = { } ) => {
707729 let tagsInUrlFormat = [ ] ;
708730 tags &&
709731 tags . forEach ( ( tag , index ) => {
710732 let tagGruop = tag ;
711- if ( typeof tag === 'object' ) {
712- tagGruop = tag ?. values . map (
713- ( value ) => `tags= ${ encodeURIComponent ( ` ${ tag . category } /${ value . tagKey } =${ value . value } `) } ` ,
733+ if ( typeof tag === 'object' && tag !== null ) {
734+ tagGruop = tag ?. values . map ( ( value ) =>
735+ buildTagsQuerySegment ( ` ${ tag . category } /${ value . tagKey } =${ value . value } `) ,
714736 ) ;
715737 tagsInUrlFormat [ index ] = ( Array . isArray ( tagGruop ) && flatten ( tagGruop ) ) || tagGruop ;
716- } else {
717- tagsInUrlFormat [ index ] = `tags= ${ encodeURIComponent ( tagGruop ) } ` ;
738+ } else if ( typeof tag === 'string' ) {
739+ tagsInUrlFormat [ index ] = buildTagsQuerySegment ( tagGruop ) ;
718740 }
719741 } ) ;
720742
@@ -730,7 +752,9 @@ export const mapGlobalFilters = (tags, workloads = {}) => {
730752 } ) ,
731753 } ;
732754
733- tagsInUrlFormat && ( globalFilterConfig . selectedTags = tagsInUrlFormat ) ;
755+ if ( tagsInUrlFormat ?. length ) {
756+ globalFilterConfig . selectedTags = flatten ( tagsInUrlFormat ) . filter ( Boolean ) ;
757+ }
734758
735759 return globalFilterConfig ;
736760} ;
0 commit comments