Example #1
0
 public void SanitizeUndefinedHeaderIgnored()
 {
     OpAttributeSanitizer.Sanitize(
         JObject.Parse("{header: undefined}")
         ).Should().BeEquivalentTo(
         new OpAttributes(),
         opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
 }
Example #2
0
        public void SanitizeSanitizesAttributes()
        {
            var attrs = JObject.Parse(@"{
                bold: 'nonboolval',
                color: '#12345H',
                background: '#333',
                font: 'times new roman',
                size: 'x.large',
                link: 'http://<',
                script: 'supper',
                list: 'ordered',
                header: '3',
                indent: 40,
                direction: 'rtl',
                align: 'center',
                width: '3',
                customAttr1:'shouldnt be touched',
                mentions: true,
                mention: {
                   'class': 'A-cls-9',
                   id: 'An-id_9:.',
                   target: '_blank',
                   avatar: 'http://www.yahoo.com',
                   'end-point': 'http://abc.com',
                   slug: 'my-name'
                }
            }");

            var result = OpAttributeSanitizer.Sanitize(attrs);

            result.Should().BeEquivalentTo(new OpAttributes()
            {
                Bold             = null, // original parses guff as "truthy" -- being more strict seems ok
                Background       = "#333",
                Font             = "times new roman",
                Link             = "http://<",
                List             = ListType.Ordered,
                Header           = 3,
                Indent           = 30,
                Direction        = DirectionType.Rtl,
                Align            = AlignType.Center,
                Width            = "3",
                CustomAttributes = new Dictionary <string, JToken>()
                {
                    { "customAttr1", JValue.CreateString("shouldnt be touched") }
                },
                Mentions = true,
                Mention  = new Mention()
                {
                    Class    = "A-cls-9",
                    Id       = "An-id_9:.",
                    Target   = "_blank",
                    Avatar   = "http://www.yahoo.com",
                    EndPoint = "http://abc.com",
                    Slug     = "my-name"
                }
            }, opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
        }
Example #3
0
        public void SanitizeIgnoresMentionsWithoutMention()
        {
            var attrs  = JObject.Parse(@"{
                mentions: true
            }");
            var result = OpAttributeSanitizer.Sanitize(attrs);

            result.Should().BeEquivalentTo(new OpAttributes(),
                                           opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
        }
Example #4
0
 public void SanitizeIndent()
 {
     OpAttributeSanitizer.Sanitize(
         JObject.Parse("{indent: 2}")
         ).Should().BeEquivalentTo(
         new OpAttributes()
     {
         Indent = 2
     },
         opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
 }
Example #5
0
 public void SanitizeDirectionRtl()
 {
     OpAttributeSanitizer.Sanitize(
         JObject.Parse("{direction: \"rtl\"}")
         ).Should().BeEquivalentTo(
         new OpAttributes()
     {
         Direction = DirectionType.Rtl
     },
         opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
 }
Example #6
0
 public void SanitizeAlignCenter()
 {
     OpAttributeSanitizer.Sanitize(
         JObject.Parse("{align: \"center\"}")
         ).Should().BeEquivalentTo(
         new OpAttributes()
     {
         Align = AlignType.Center
     },
         opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
 }
Example #7
0
 public void SanitizeHeader100ClampsTo6()
 {
     OpAttributeSanitizer.Sanitize(
         JObject.Parse("{header: 100}")
         ).Should().BeEquivalentTo(
         new OpAttributes()
     {
         Header = 6
     },
         opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
 }
Example #8
0
 public void SanitizeDuffInputReturnsEmptyObject()
 {
     OpAttributeSanitizer.Sanitize(null)
     .Should().BeEquivalentTo(new OpAttributes(),
                              opts => opts.RespectingRuntimeTypes());
     OpAttributeSanitizer.Sanitize(new JValue(3))
     .Should().BeEquivalentTo(new OpAttributes());
     OpAttributeSanitizer.Sanitize(JValue.CreateUndefined())
     .Should().BeEquivalentTo(new OpAttributes());
     OpAttributeSanitizer.Sanitize(new JValue("fd"))
     .Should().BeEquivalentTo(new OpAttributes());
 }
Example #9
0
        public void SanitizeHandlesCustomAttributes()
        {
            var attrs  = JObject.Parse(@"{
                customAttr1: 'attr1',
                customAttr2: 'attr2',
            }");
            var result = OpAttributeSanitizer.Sanitize(attrs);

            result.Should().BeEquivalentTo(new OpAttributes()
            {
                CustomAttributes = new Dictionary <string, JToken>()
                {
                    { "customAttr1", JValue.CreateString("attr1") },
                    { "customAttr2", JValue.CreateString("attr2") }
                },
            }, opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
        }
Example #10
0
        public void SanitizeIgnoresMentionsFalse()
        {
            var attrs  = JObject.Parse(@"{
                mentions: false,
                mention: {
                   'class': 'A-cls-9',
                   id: 'An-id_9:.',
                   target: '_blank',
                   avatar: 'http://www.yahoo.com',
                   'end-point': 'http://abc.com',
                   slug: 'my-name'
                }
            }");
            var result = OpAttributeSanitizer.Sanitize(attrs);

            result.Should().BeEquivalentTo(new OpAttributes(),
                                           opts => opts.RespectingRuntimeTypes().WithStrictOrdering());
        }