@@ -491,15 +491,27 @@ UI.utils.label = function (x, initialCap) { // x is an object
491491 }
492492 var s = x . uri
493493 if ( typeof s == 'undefined' ) return x . toString ( ) ; // can't be a symbol
494- s = decodeURI ( s )
495- if ( s . slice ( - 5 ) == '#this' ) s = s . slice ( 0 , - 5 )
496- else if ( s . slice ( - 3 ) == '#me' ) s = s . slice ( 0 , - 3 )
494+ // s = decodeURI(s) // This can crash is random valid @ signs are presentation
495+ // The idea was to clean up eg URIs encoded in query strings
496+ // Also encoded character in what was filenames like @ [] {}
497+ try {
498+ s = s . split ( '/' ) . map ( decodeURIComponent ) . join ( '/' ) // If it is properly encoded
499+ } catch ( e ) { // try individual decoding of ASCII code points
500+ for ( var i = s . length - 3 ; i > 0 ; i -- ) {
501+ const hex = '0123456789abcefABCDEF' // The while upacks multiple layers of encoding
502+ while ( s [ i ] === '%' && hex . indexOf ( s [ i + 1 ] ) >= 0 && hex . indexOf ( s [ i + 2 ] ) >= 0 ) {
503+ s = s . slice ( 0 , i ) + String . fromCharCode ( parseInt ( s . slice ( i + 1 , i + 3 ) , 16 ) ) + s . slice ( i + 3 )
504+ }
505+ }
506+ }
507+ if ( s . slice ( - 5 ) === '#this' ) s = s . slice ( 0 , - 5 )
508+ else if ( s . slice ( - 3 ) === '#me' ) s = s . slice ( 0 , - 3 )
497509
498510 var hash = s . indexOf ( '#' )
499511 if ( hash >= 0 ) return cleanUp ( s . slice ( hash + 1 ) )
500512
501- if ( s . slice ( - 9 ) == '/foaf.rdf' ) s = s . slice ( 0 , - 9 )
502- else if ( s . slice ( - 5 ) == '/foaf' ) s = s . slice ( 0 , - 5 )
513+ if ( s . slice ( - 9 ) === '/foaf.rdf' ) s = s . slice ( 0 , - 9 )
514+ else if ( s . slice ( - 5 ) === '/foaf' ) s = s . slice ( 0 , - 5 )
503515
504516 if ( 1 ) { // Eh? Why not do this? e.g. dc:title needs it only trim URIs, not rdfs:labels
505517 var slash = s . lastIndexOf ( '/' , s . length - 2 ) ; // (len-2) excludes trailing slash
0 commit comments