create-prisma-php-app 3.2.1 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -202,9 +202,12 @@ class TemplateCompiler
202
202
 
203
203
  private static function protectInlineScripts(string $html): string
204
204
  {
205
- return preg_replace_callback(
206
- '#<script\b([^>]*?)>(.*?)</script>#is',
207
- static function ($m) {
205
+ if (stripos($html, '<script') === false) {
206
+ return $html;
207
+ }
208
+
209
+ $processScripts = static function (string $content): string {
210
+ $callback = static function (array $m): string {
208
211
  if (preg_match('/\bsrc\s*=/i', $m[1])) {
209
212
  return $m[0];
210
213
  }
@@ -233,9 +236,33 @@ class TemplateCompiler
233
236
  $code = str_replace(']]>', ']]]]><![CDATA[>', $m[2]);
234
237
 
235
238
  return "<script{$m[1]}><![CDATA[\n{$code}\n]]></script>";
236
- },
237
- $html
238
- );
239
+ };
240
+
241
+ $result = preg_replace_callback(
242
+ '#<script\b([^>]*?)>(.*?)</script>#is',
243
+ $callback,
244
+ $content
245
+ );
246
+
247
+ if ($result === null) {
248
+ $result = preg_replace_callback(
249
+ '#<script\b([^>]*?)>(.*?)</script>#is',
250
+ $callback,
251
+ $content
252
+ );
253
+
254
+ return $result ?? $content;
255
+ }
256
+
257
+ return $result;
258
+ };
259
+
260
+ if (preg_match('/^(.*?<body\b[^>]*>)(.*?)(<\/body>.*)$/is', $html, $parts)) {
261
+ [$all, $beforeBody, $body, $afterBody] = $parts;
262
+ return $beforeBody . $processScripts($body) . $afterBody;
263
+ }
264
+
265
+ return $processScripts($html);
239
266
  }
240
267
 
241
268
  public static function innerXml(DOMNode $node): string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",