Просмотр исходного кода

Fix JavaScript syntax error in sanitizeId function

- Fix escaped quotes and regex patterns in JavaScript within PHP string
- Properly escape backslashes and quotes for JavaScript embedded in PHP
- Replace problematic regex backreference with explicit string manipulation
mgomon 7 месяцев назад
Родитель
Сommit
92fe8cc439
1 измененных файлов с 3 добавлено и 3 удалено
  1. 3 3
      api/homepage/jellystat.php

+ 3 - 3
api/homepage/jellystat.php

@@ -467,11 +467,11 @@ trait JellyStatHomepageItem
         
         // Helper function to sanitize IDs for use in HTML attributes and CSS selectors
         function sanitizeId(id) {
-            if (!id) return 'jellystat-unknown';
+            if (!id) return \'jellystat-unknown\';
             // Convert to string and replace problematic characters
             return String(id)
-                .replace(/[^a-zA-Z0-9\-_]/g, '_') // Replace special chars with underscores
-                .replace(/^[0-9]/, '_$&') // Prefix with underscore if starts with number
+                .replace(/[^a-zA-Z0-9\\-_]/g, \'_\') // Replace special chars with underscores
+                .replace(/^[0-9]/, \'_\' + String(id).charAt(0)) // Prefix with underscore if starts with number
                 .toLowerCase();
         }