This project has moved. For the latest updates, please go here.

Null characters in strings not passed between host and script

Apr 6, 2014 at 9:45 AM
Hi,

It seems that null characters in strings, that are valid in both .Net and JavaScript, are not passed between host and script in both directions.

For example:
class StringTest
    {
        public static int GetLength(string s)
        {
            return s.Length;
        }
    }

...

engine.AddHostType("Console", typeof(Console));

// Test JS string passed to host
engine.AddHostType("StringTest", typeof(StringTest));

engine.Execute(@"
var jsString = 'ab\0cd';
Console.WriteLine('JS length of jsString {0}', jsString.length);
Console.WriteLine('Host length of jsString: {0}', StringTest.GetLength(jsString));
"
);

// Test Host string passed to JS
string hostString = "ef\0gh";
Console.WriteLine("Host length of hostString: {0}", hostString.Length);
engine.Execute("function jsLength(s) {Console.WriteLine('JS length of hostString: {0}', s.length);}");
engine.Script.jsLength(hostString);
The output I get is:

JS length of jsString 5
Host length of jsString: 2 <---- Wrong, should be 5
Host length of hostString: 5
JS length of hostString: 2 <---- Wrong, should be 5


Thanks in advance,
Ron
Coordinator
Apr 7, 2014 at 3:07 AM
Hi Ron,

You're right. A fix is on the way.

Cheers!
Coordinator
Apr 10, 2014 at 11:59 AM
Ron,

The fix is now available.

Thanks again!
Marked as answer by Zcodez on 4/15/2014 at 8:03 AM