Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Null characters in strings not passed between host and script

$
0
0
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

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>