diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-08 10:51:01 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-08 10:51:01 +0900 |
| commit | c06d46eae30c9468535fb6af5e9b822acadbbdb6 (patch) | |
| tree | c4c740f0cccd15f825596f7a115f3b8f8eb8ffa7 /worker | |
| parent | 32344d99c473b634c37f5d11e52ef389d46d4510 (diff) | |
| download | phperkaigi-2025-albatross-c06d46eae30c9468535fb6af5e9b822acadbbdb6.tar.gz phperkaigi-2025-albatross-c06d46eae30c9468535fb6af5e9b822acadbbdb6.tar.zst phperkaigi-2025-albatross-c06d46eae30c9468535fb6af5e9b822acadbbdb6.zip | |
trim php tag before execution
Diffstat (limited to 'worker')
| -rw-r--r-- | worker/exec.mjs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/worker/exec.mjs b/worker/exec.mjs index 7d64cc3..fc0accd 100644 --- a/worker/exec.mjs +++ b/worker/exec.mjs @@ -1,12 +1,23 @@ import PHPWasm from "./php-wasm.js"; -process.once("message", async ({ code, input }) => { +process.once("message", async ({ code: originalCode, input }) => { const PRELUDE = ` define('STDIN', fopen('php://stdin', 'r')); define('STDOUT', fopen('php://stdout', 'r')); define('STDERR', fopen('php://stderr', 'r')); `; + + // remove php tag + let code; + if (originalCode.startsWith("<?php")) { + code = PRELUDE + originalCode.slice(5); + } else if (originalCode.startsWith("<?")) { + code = PRELUDE + originalCode.slice(2); + } else { + code = PRELUDE + originalCode; + } + const BUFFER_MAX = 1024; let stdinPos = 0; // bytewise @@ -52,7 +63,7 @@ process.once("message", async ({ code, input }) => { let err; let result; try { - result = ccall("php_wasm_run", "number", ["string"], [PRELUDE + code]); + result = ccall("php_wasm_run", "number", ["string"], [code]); } catch (e) { err = e; } |
