Skip to content

Commit ecda61e

Browse files
Andrew Bakerclaude
andcommitted
v1.7.44 — Fix JS crash in renderAssets: WP script src can be false not string
WordPress registers scripts/styles with src=false (inline-only assets). PHP ?? operator doesn't catch false, so false was JSON-encoded as boolean and passed to JS where .replace() and .toLowerCase() don't exist on it. - PHP: use is_string() guard, cast to '' when not a string - JS: String() coerce in truncate(), truncateUrl(), assets filter loop Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6fe70fe commit ecda61e

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

assets/cs-perf-monitor.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@
266266

267267
rows = rows.filter(function (r) {
268268
if (pluginFilter && r.plugin !== pluginFilter) return false;
269-
if (search && r.handle.toLowerCase().indexOf(search) === -1
270-
&& r.src.toLowerCase().indexOf(search) === -1
271-
&& r.plugin.toLowerCase().indexOf(search) === -1) return false;
269+
if (search && String(r.handle).toLowerCase().indexOf(search) === -1
270+
&& String(r.src).toLowerCase().indexOf(search) === -1
271+
&& String(r.plugin).toLowerCase().indexOf(search) === -1) return false;
272272
return true;
273273
});
274274

@@ -1157,12 +1157,12 @@
11571157
}
11581158
function truncate(str, max) {
11591159
if (!str) return '';
1160-
var s = str.replace(/\s+/g, ' ').trim();
1160+
var s = String(str).replace(/\s+/g, ' ').trim();
11611161
return s.length > max ? s.slice(0, max - 1) + '\u2026' : s;
11621162
}
11631163
function truncateUrl(url, max) {
11641164
try {
1165-
var u = new URL(url), out = u.hostname + u.pathname;
1165+
var u = new URL(String(url)), out = u.hostname + u.pathname;
11661166
if (u.search) out += u.search.slice(0, 20) + (u.search.length > 20 ? '\u2026' : '');
11671167
return out.length > max ? out.slice(0, max - 1) + '\u2026' : out;
11681168
} catch(e) { return truncate(url, max); }

cs-code-block.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: CloudScale Code Block
44
* Plugin URI: https://andrewbaker.ninja
55
* Description: Syntax highlighted code block with auto language detection, clipboard copy, dark/light mode toggle, code block migrator, and read only SQL query tool. Works as a Gutenberg block and as a [cs_code] shortcode.
6-
* Version: 1.7.43
6+
* Version: 1.7.44
77
* Author: Andrew Baker
88
* Author URI: https://andrewbaker.ninja
99
* License: GPL-2.0-or-later
@@ -38,7 +38,7 @@
3838
*/
3939
class CloudScale_Code_Block {
4040

41-
const VERSION = '1.7.43';
41+
const VERSION = '1.7.44';
4242
const HLJS_VERSION = '11.11.1';
4343
const HLJS_CDN = 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/';
4444
const TOOLS_SLUG = 'cloudscale-code-sql';
@@ -1712,19 +1712,20 @@ private static function perf_build_assets_data(): array {
17121712
$scripts_obj = wp_scripts();
17131713
$styles_obj = wp_styles();
17141714

1715+
// WP registers scripts/styles with src=false (inline-only); cast to string
1716+
// so the JS side always receives a string, never a boolean false.
17151717
$scripts = [];
17161718
foreach ( $scripts_obj->done as $handle ) {
17171719
if ( ! isset( $scripts_obj->registered[ $handle ] ) ) {
17181720
continue;
17191721
}
17201722
$dep = $scripts_obj->registered[ $handle ];
1721-
$src = $dep->src ?? '';
1723+
$src = is_string( $dep->src ) ? $dep->src : '';
17221724
$scripts[] = [
1723-
'handle' => $handle,
1725+
'handle' => (string) $handle,
17241726
'src' => $src,
17251727
'plugin' => self::perf_attr_asset( $src ),
1726-
'ver' => $dep->ver ?? '',
1727-
'deps' => $dep->deps ?? [],
1728+
'ver' => is_string( $dep->ver ) ? $dep->ver : ( $dep->ver ? (string) $dep->ver : '' ),
17281729
];
17291730
}
17301731

@@ -1734,12 +1735,12 @@ private static function perf_build_assets_data(): array {
17341735
continue;
17351736
}
17361737
$dep = $styles_obj->registered[ $handle ];
1737-
$src = $dep->src ?? '';
1738+
$src = is_string( $dep->src ) ? $dep->src : '';
17381739
$styles[] = [
1739-
'handle' => $handle,
1740+
'handle' => (string) $handle,
17401741
'src' => $src,
17411742
'plugin' => self::perf_attr_asset( $src ),
1742-
'ver' => $dep->ver ?? '',
1743+
'ver' => is_string( $dep->ver ) ? $dep->ver : ( $dep->ver ? (string) $dep->ver : '' ),
17431744
];
17441745
}
17451746

readme.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: code block, syntax highlighting, gutenberg block, dark mode, highlight.js
44
Requires at least: 6.0
55
Tested up to: 6.7
66
Requires PHP: 7.4
7-
Stable tag: 1.7.43
7+
Stable tag: 1.7.44
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -79,7 +79,7 @@ Yes. Press Enter to run the query. Use Shift+Enter to insert a newline. Ctrl+Ent
7979

8080
== Changelog ==
8181

82-
= 1.7.43 =
82+
= 1.7.44 =
8383
* Added: CS Monitor — Assets tab showing all enqueued JS and CSS files with plugin attribution, type filter, and search
8484
* Added: CS Monitor — Hooks tab showing top 50 hooks by cumulative time, with sortable columns and search
8585
* Added: CS Monitor — Object cache stats card in Summary (hit rate, hits/misses, persistent cache detection)

0 commit comments

Comments
 (0)