<commit_before>using System;
using System.Text.RegularExpressions;

namespace Nustache.Core
{
    public class VariableReference : Part
    {
        private static readonly Regex _notEscapedRegex = new Regex(@"^\{\s*(.+?)\s*\}$");
        private readonly string _path;
        private readonly bool _escaped;

        public VariableReference(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            _path = path;

            var match = _notEscapedRegex.Match(path);
            _escaped = !match.Success;

            if (match.Success)
            {
                _path = match.Groups[1].Value;
            }

            if (_path.StartsWith("&"))
            {
                _escaped = false;
                _path = _path.Substring(1).Trim();
            }
        }

        public string Path { get { return _path; } }
        public bool Escaped { get { return _escaped; } }

        public override void Render(RenderContext context)
        {
            var value = context.GetValue(_path);

            var lambda = value as Lambda<string>;
            if(lambda != null) 
            {
                var lambdaResult = lambda();
                using (System.IO.TextReader sr = new System.IO.StringReader(lambdaResult))
                {
                    var template = new Template();
                    template.Load(sr);
                    context.Enter(template);
                    template.Render(context);
                    context.Exit();

                    return;
                }
            }

            var helper = value as HelperProxy;<commit_msg>Fixed escaping characters when using Lambda #84<commit_after>using System;
using System.Text.RegularExpressions;

namespace Nustache.Core
{
    public class VariableReference : Part
    {
        private static readonly Regex _notEscapedRegex = new Regex(@"^\{\s*(.+?)\s*\}$");
        private readonly string _path;
        private readonly bool _escaped;

        public VariableReference(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            _path = path;

            var match = _notEscapedRegex.Match(path);
            _escaped = !match.Success;

            if (match.Success)
            {
                _path = match.Groups[1].Value;
            }

            if (_path.StartsWith("&"))
            {
                _escaped = false;
                _path = _path.Substring(1).Trim();
            }
        }

        public string Path { get { return _path; } }
        public bool Escaped { get { return _escaped; } }

        public override void Render(RenderContext context)
        {
            var value = context.GetValue(_path);

            var lambda = value as Lambda<string>;
            if(lambda != null) 
            {
                var lambdaResult = lambda();

                lambdaResult = _escaped
                    ? Encoders.HtmlEncode(lambdaResult.ToString())
                    : lambdaResult.ToString(); 

                using (System.IO.TextReader sr = new System.IO.StringReader(lambdaResult))
                {
                    var template = new Template();
                    template.Load(sr);
                    context.Enter(template);
                    template.Render(context);
                    context.Exit();

                    return;
                }
            }

            var helper = value as HelperProxy;
{'fraction_non_alphanumeric': 0.09230769230769231, 'fraction_numerical': 0.0016783216783216783, 'mean_word_length': 1.3372549019607842, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3810909', 'n_tokens_mistral': 921, 'n_tokens_neox': 838, 'n_words': 209}