MCPcopy Create free account
hub / github.com/error311/FileRise / sanitizeLogoUrl

Function sanitizeLogoUrl

public/js/adminPanel.js:550–581  ·  view source on GitHub ↗
(raw)

Source from the content-addressed store, hash-verified

548 if (!logoImg) return;
549
550 const sanitizeLogoUrl = (raw) => {
551 let url = (raw || '').trim();
552 if (!url) return '';
553
554 // If they used a bare "uploads/..." path, normalize to "/uploads/..."
555 if (!url.startsWith('/') && url.startsWith('uploads/')) {
556 url = '/' + url;
557 }
558
559 const legacyMatch = url.match(/\/uploads\/profile_pics\/([^?#]+)/);
560 if (legacyMatch && legacyMatch[1]) {
561 let legacyName = legacyMatch[1];
562 try { legacyName = decodeURIComponent(legacyName); } catch (e) {}
563 url = `/api/public/profilePic.php?file=${encodeURIComponent(legacyName)}`;
564 }
565
566 // Strip any CR/LF just in case
567 url = url.replace(/[\r\n]+/g, '');
568
569 if (url.startsWith('/')) {
570 if (url.includes('://')) return '';
571 return withBase(url);
572 }
573
574 try {
575 const parsed = new URL(url);
576 if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return '';
577 return parsed.toString();
578 } catch (e) {
579 return '';
580 }
581 };
582
583 const safeUrl = sanitizeLogoUrl((input && input.value) || '');
584

Callers 1

Calls 1

withBaseFunction · 0.85

Tested by

no test coverage detected