1
Vote

Error parsing razor when text is preceded by "<"

description

When a razor template has a variable wrapped in parenthesis (ex. "(@Model.B)" in the code below), the razor engine fails to compile and replace that variable if it is preceded by a "<" and separated by space or text. Is this intended behavior?
        [Test]
        public void TestWeirdLangleBracketError()
        {
            var template = "(@Model.B)";
            var model = new Model { B = Guid.NewGuid().ToString() };
            var templateService =
                new TemplateService(new TemplateServiceConfiguration { EncodedStringFactory = new RawStringFactory() });

            //It is replaced here
            templateService.Compile(template, typeof(Model), "Try1");
            Assert.True(templateService.Run("Try1", model, null).Contains(model.B));
            //But not here
            templateService.Compile(" < " + template, typeof(Model), "Try2");
            Assert.False(templateService.Run("Try2", model, null).Contains(model.B));
        }

        public class Model
        {
            public int A { get; set; }
            public string B { get; set; }
        }

comments