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

Method sanitizeLogoUrl

src/FileRise/Domain/AdminModel.php:106–131  ·  view source on GitHub ↗

Allow logo URLs that are either site-relative or http(s). */

($url)

Source from the content-addressed store, hash-verified

104
105 /** Allow logo URLs that are either site-relative or http(s). */
106 private static function sanitizeLogoUrl($url): string
107 {
108 $url = trim((string)$url);
109 if ($url === '') {
110 return '';
111 }
112
113 // Normalize plain relative paths (no scheme, no leading slash) to site-root form.
114 if ($url[0] !== '/' && !preg_match('~^[a-z][a-z0-9+.\-]*:~i', $url)) {
115 $url = '/' . ltrim($url, '/');
116 }
117
118 // 1) Site-relative (normalize legacy /uploads/profile_pics to the public API)
119 if ($url[0] === '/') {
120 // Strip CRLF just in case
121 $url = preg_replace('~[\r\n]+~', '', $url);
122 // Don’t allow sneaky schemes embedded in a relative path
123 if (strpos($url, '://') !== false) {
124 return '';
125 }
126 return fr_normalize_profile_pic_url($url);
127 }
128
129 // 2) Fallback to plain http(s) validation
130 return self::sanitizeHttpUrl($url);
131 }
132
133 private static function normalizeDefaultLanguage($lang): string
134 {

Callers 3

buildPublicSubsetMethod · 0.95
updateConfigMethod · 0.95
getConfigMethod · 0.95

Calls 2

sanitizeHttpUrlMethod · 0.95

Tested by

no test coverage detected