Repository: metacall/core (language: rust)

Issue:
bug: incorrectly calculating the size of script that is loaded from memory
## 🐛 Bug Report
the script that is loaded from memory lost the last character because its size is not correct and misses a one-character from its length. 

### Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->

https://github.com/metacall/core/blob/76f02c051c9bfd84926331f8ada8b9506a12f04d/source/ports/rs_port/src/loaders.rs#L82-L87

```diff
 metacall_load_from_memory( 
     c_tag.as_ptr(), 
     c_script.as_ptr(), 
-    script.len(), 
+    script.len() + 1, 
     ptr::null_mut(), 
)
```

### Steps to Reproduce

#### source code
```rust
use metacall::{loaders, switch};
fn main() {
    let _metacall = switch::initialize().unwrap();
    loaders::from_memory("node", "console.log('Hello world')").unwrap();
}
```

#### behavior
```
Exception in node_loader_trampoline_load_from_memory while loading: console.log('Hello world' 0x5b3b086100b0-0x5b3b08610080-26-2913836576:1
console.log('Hello world'
            ^^^^^^^^^^^^^

SyntaxError: missing ) after argument list
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1274:20)
    at Module._compile (node:internal/modules/cjs/loader:1320:27)
    at node_loader_trampoline_load_from_memory (/gnu/store/ka685gr3ah26nmjfny1kwixmv2nsc2ms-metacall-0.7.8/lib/bootstrap.js:182:5)
```



Discussion / hints:
@devraymondsh take a look

Fix patch:
diff --git a/source/ports/rs_port/src/loaders.rs b/source/ports/rs_port/src/loaders.rs
index cf0cec127..eb691acbb 100644
--- a/source/ports/rs_port/src/loaders.rs
+++ b/source/ports/rs_port/src/loaders.rs
@@ -82,7 +82,7 @@ pub fn from_memory(tag: impl ToString, script: impl ToString) -> Result<(), Meta
         metacall_load_from_memory(
             c_tag.as_ptr(),
             c_script.as_ptr(),
-            script.len(),
+            script.len() + 1,
             ptr::null_mut(),
         )
     } != 0


Test patch:
diff --git a/source/ports/rs_port/tests/inlines_test.rs b/source/ports/rs_port/tests/inlines_test.rs
index fa0f45e97..fe7c9cb15 100644
--- a/source/ports/rs_port/tests/inlines_test.rs
+++ b/source/ports/rs_port/tests/inlines_test.rs
@@ -12,16 +12,25 @@ fn inlines() {
             print("hello world")
         }
     }
+    if loaders::from_memory("py", "").is_ok() {
+        py! {print("hello world")}
+    }
 
     if loaders::from_memory("node", "").is_ok() {
         node! {
             console.log("hello world");
         }
     }
+    if loaders::from_memory("node", "").is_ok() {
+        node! {console.log("hello world")}
+    }
 
     if loaders::from_memory("ts", "").is_ok() {
         ts! {
             console.log("hello world");
         }
     }
+    if loaders::from_memory("ts", "").is_ok() {
+        ts! {console.log("hello world")}
+    }
 }
diff --git a/source/ports/rs_port/tests/loaders_test.rs b/source/ports/rs_port/tests/loaders_test.rs
index 75873d8c5..0ed57931b 100644
--- a/source/ports/rs_port/tests/loaders_test.rs
+++ b/source/ports/rs_port/tests/loaders_test.rs
@@ -8,9 +8,9 @@ use std::{
 
 // Two different names to avoid conflicts when testing both load_from_memory and load_from_files
 // in a single test.
-const SCRIPT1: &str = "function greet1() { return 'hi there!' } \nmodule.exports = { greet1 };";
+const SCRIPT1: &str = "function greet1() { return 'hi there!' } \nmodule.exports = { greet1 }";
 const SCRIPT2: &str = "function greet2() { return 'hi there!' } \nmodule.exports = { greet2 };";
-
+const SCRIPT3: &str = "console.log('Hello world')";
 fn call_greet(test: &str, num: u32) {
     let out = metacall_no_arg::<String>(format!("greet{}", num)).unwrap();
     if out.as_str() == "hi there!" {
@@ -25,8 +25,9 @@ fn call_greet(test: &str, num: u32) {
 
 fn load_from_memory_test() {
     loaders::from_memory("node", SCRIPT1).unwrap();
-
     call_greet("load_from_memory", 1);
+
+    loaders::from_memory("node", SCRIPT3).unwrap();
 }
 
 fn load_from_file_test() {
@@ -51,7 +52,6 @@ fn load_from_file_test() {
 #[test]
 fn loaders() {
     let _d = switch::initialize().unwrap();
-
     // Testing load_from_memory
     load_from_memory_test();