コード例 #1
0
ファイル: UdiTests.cs プロジェクト: soreng/Umbraco-CMS
        public void StringEncodingTest()
        {
            // absolute path is unescaped
            var uri = new Uri("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test");

            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/this is a test", uri.ToString());
            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test", uri.AbsoluteUri);
            Assert.AreEqual("/this%20is%20a%20test", uri.AbsolutePath);

            Assert.AreEqual("/this is a test", Uri.UnescapeDataString(uri.AbsolutePath));
            Assert.AreEqual("%2Fthis%20is%20a%20test", Uri.EscapeDataString("/this is a test"));
            Assert.AreEqual("/this%20is%20a%20test", Uri.EscapeUriString("/this is a test"));

            var udi = UdiParser.Parse("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test");

            Assert.AreEqual(Constants.UdiEntityType.AnyString, udi.EntityType);
            Assert.IsInstanceOf <StringUdi>(udi);
            var stringEntityId = udi as StringUdi;

            Assert.IsNotNull(stringEntityId);
            Assert.AreEqual("this is a test", stringEntityId.Id);
            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/this%20is%20a%20test", udi.ToString());

            var udi2 = new StringUdi(Constants.UdiEntityType.AnyString, "this is a test");

            Assert.AreEqual(udi, udi2);

            var udi3 = new StringUdi(Constants.UdiEntityType.AnyString, "path to/this is a test.xyz");

            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/path%20to/this%20is%20a%20test.xyz", udi3.ToString());
        }
コード例 #2
0
    public override object?ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
    {
        var jo  = JToken.ReadFrom(reader);
        var val = jo.ToObject <string>();

        return(val == null ? null : UdiParser.Parse(val, true));
    }
コード例 #3
0
ファイル: UdiTests.cs プロジェクト: soreng/Umbraco-CMS
        public void RootUdiTest()
        {
            var stringUdi = new StringUdi(Constants.UdiEntityType.AnyString, string.Empty);

            Assert.IsTrue(stringUdi.IsRoot);
            Assert.AreEqual("umb://any-string/", stringUdi.ToString());

            var guidUdi = new GuidUdi(Constants.UdiEntityType.AnyGuid, Guid.Empty);

            Assert.IsTrue(guidUdi.IsRoot);
            Assert.AreEqual("umb://any-guid/00000000000000000000000000000000", guidUdi.ToString());

            var udi = UdiParser.Parse("umb://any-string/");

            Assert.IsTrue(udi.IsRoot);
            Assert.IsInstanceOf <StringUdi>(udi);

            udi = UdiParser.Parse("umb://any-guid/00000000000000000000000000000000");
            Assert.IsTrue(udi.IsRoot);
            Assert.IsInstanceOf <GuidUdi>(udi);

            udi = UdiParser.Parse("umb://any-guid/");
            Assert.IsTrue(udi.IsRoot);
            Assert.IsInstanceOf <GuidUdi>(udi);
        }
コード例 #4
0
        public void Convert_Valid_Json()
        {
            BlockListPropertyValueConverter editor       = CreateConverter();
            BlockListConfiguration          config       = ConfigForMany();
            IPublishedPropertyType          propertyType = GetPropertyType(config);
            IPublishedElement publishedElement           = Mock.Of <IPublishedElement>();

            string json      = @"
{
    layout: {
        '" + Constants.PropertyEditors.Aliases.BlockList + @"': [
            {
                'contentUdi': 'umb://element/1304E1DDAC87439684FE8A399231CB3D'
            }
        ]
    },
        contentData: [
        {
            'contentTypeKey': '" + _contentKey1 + @"',
            'udi': 'umb://element/1304E1DDAC87439684FE8A399231CB3D'
        }
    ]
}";
            var    converted = editor.ConvertIntermediateToObject(publishedElement, propertyType, PropertyCacheLevel.None, json, false) as BlockListModel;

            Assert.IsNotNull(converted);
            Assert.AreEqual(1, converted.Count);
            IPublishedElement item0 = converted[0].Content;

            Assert.AreEqual(Guid.Parse("1304E1DD-AC87-4396-84FE-8A399231CB3D"), item0.Key);
            Assert.AreEqual("Test1", item0.ContentType.Alias);
            Assert.IsNull(converted[0].Settings);
            Assert.AreEqual(UdiParser.Parse("umb://element/1304E1DDAC87439684FE8A399231CB3D"), converted[0].ContentUdi);
        }
コード例 #5
0
ファイル: UdiTests.cs プロジェクト: soreng/Umbraco-CMS
        public void GuidUdiParseTest()
        {
            var guid = Guid.NewGuid();
            var s    = "umb://" + Constants.UdiEntityType.AnyGuid + "/" + guid.ToString("N");
            var udi  = UdiParser.Parse(s);

            Assert.AreEqual(Constants.UdiEntityType.AnyGuid, udi.EntityType);
            Assert.IsInstanceOf <GuidUdi>(udi);
            var gudi = udi as GuidUdi;

            Assert.IsNotNull(gudi);
            Assert.AreEqual(guid, gudi.Guid);
            Assert.AreEqual(s, udi.ToString());
        }
コード例 #6
0
ファイル: UdiTests.cs プロジェクト: soreng/Umbraco-CMS
        public void StringUdiParseTest()
        {
            var udi = UdiParser.Parse("umb://" + Constants.UdiEntityType.AnyString + "/test-id");

            Assert.AreEqual(Constants.UdiEntityType.AnyString, udi.EntityType);
            Assert.IsInstanceOf <StringUdi>(udi);
            var stringEntityId = udi as StringUdi;

            Assert.IsNotNull(stringEntityId);
            Assert.AreEqual("test-id", stringEntityId.Id);
            Assert.AreEqual("umb://" + Constants.UdiEntityType.AnyString + "/test-id", udi.ToString());

            udi = UdiParser.Parse("umb://" + Constants.UdiEntityType.AnyString + "/DA845952BE474EE9BD6F6194272AC750");
            Assert.IsInstanceOf <StringUdi>(udi);
        }
コード例 #7
0
    public void Returns_Udis_From_Data_Udi_Html_Attributes()
    {
        var input = @"<p>
    <div>
        <img src='/media/12312.jpg' data-udi='umb://media/D4B18427A1544721B09AC7692F35C264' />
    </div>
</p><p><img src='/media/234234.jpg' data-udi=""umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"" /></p>";

        var imageSourceParser = new HtmlImageSourceParser(Mock.Of <IPublishedUrlProvider>());

        var result = imageSourceParser.FindUdisFromDataAttributes(input).ToList();

        Assert.AreEqual(2, result.Count);
        Assert.AreEqual(UdiParser.Parse("umb://media/D4B18427A1544721B09AC7692F35C264"), result[0]);
        Assert.AreEqual(UdiParser.Parse("umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"), result[1]);
    }
コード例 #8
0
        public void Returns_Udis_From_LocalLinks()
        {
            var input = @"<p>
    <div>
        <img src='/media/12312.jpg' data-udi='umb://media/D4B18427A1544721B09AC7692F35C264' />
        <a href=""{locallink:umb://document/C093961595094900AAF9170DDE6AD442}"">hello</a>
    </div>
</p><p><img src='/media/234234.jpg' data-udi=""umb://media-type/B726D735E4C446D58F703F3FBCFC97A5"" />
<a href=""{locallink:umb://document-type/2D692FCB070B4CDA92FB6883FDBFD6E2}"">hello</a>
</p>";

            var umbracoContextAccessor = new TestUmbracoContextAccessor();
            var parser = new HtmlLocalLinkParser(umbracoContextAccessor, Mock.Of <IPublishedUrlProvider>());

            var result = parser.FindUdisFromLocalLinks(input).ToList();

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(UdiParser.Parse("umb://document/C093961595094900AAF9170DDE6AD442"), result[0]);
            Assert.AreEqual(UdiParser.Parse("umb://document-type/2D692FCB070B4CDA92FB6883FDBFD6E2"), result[1]);
        }
コード例 #9
0
        public void StringEncodingTest2()
        {
            // reserved = : / ? # [ ] @ ! $ & ' ( ) * + , ; =
            // unreserved = alpha digit - . _ ~
            Assert.AreEqual("%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2B%2C%3B%3D.-_~%25", Uri.EscapeDataString(":/?#[]@!$&'()+,;=.-_~%"));
            Assert.AreEqual(":/?#[]@!$&'()+,;=.-_~%25", Uri.EscapeUriString(":/?#[]@!$&'()+,;=.-_~%"));

            // we cannot have reserved chars at random places
            // we want to keep the / in string udis
            var r = string.Join("/", "path/to/View[1].cshtml".Split('/').Select(Uri.EscapeDataString));

            Assert.AreEqual("path/to/View%5B1%5D.cshtml", r);
            Assert.IsTrue(Uri.IsWellFormedUriString("umb://partial-view-macro/" + r, UriKind.Absolute));

            // with the proper fix in StringUdi this should work:
            var udi1 = new StringUdi("partial-view-macro", "path/to/View[1].cshtml");

            Assert.AreEqual("umb://partial-view-macro/path/to/View%5B1%5D.cshtml", udi1.ToString());
            Udi udi2 = UdiParser.Parse("umb://partial-view-macro/path/to/View%5B1%5D.cshtml");

            Assert.AreEqual("path/to/View[1].cshtml", ((StringUdi)udi2).Id);
        }
コード例 #10
0
    public PackageDefinition?ToPackageDefinition(XElement xml)
    {
        if (xml == null)
        {
            return(null);
        }

        var retVal = new PackageDefinition
        {
            Id                    = xml.AttributeValue <int>("id"),
            Name                  = xml.AttributeValue <string>("name") ?? string.Empty,
            PackagePath           = xml.AttributeValue <string>("packagePath") ?? string.Empty,
            PackageId             = xml.AttributeValue <Guid>("packageGuid"),
            ContentNodeId         = xml.Element("content")?.AttributeValue <string>("nodeId") ?? string.Empty,
            ContentLoadChildNodes = xml.Element("content")?.AttributeValue <bool>("loadChildNodes") ?? false,
            MediaUdis             =
                xml.Element("media")?.Elements("nodeUdi").Select(x => (GuidUdi)UdiParser.Parse(x.Value)).ToList() ??
                EmptyGuidUdiList,
            MediaLoadChildNodes = xml.Element("media")?.AttributeValue <bool>("loadChildNodes") ?? false,
            Macros =
                xml.Element("macros")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            Templates =
                xml.Element("templates")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            Stylesheets =
                xml.Element("stylesheets")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            Scripts =
                xml.Element("scripts")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            PartialViews =
                xml.Element("partialViews")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            DocumentTypes =
                xml.Element("documentTypes")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            MediaTypes =
                xml.Element("mediaTypes")?.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                .ToList() ?? EmptyStringList,
            Languages =
                xml.Element("languages")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            DictionaryItems =
                xml.Element("dictionaryitems")?.Value
                .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                EmptyStringList,
            DataTypes = xml.Element("datatypes")?.Value
                        .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
                        EmptyStringList,
        };

        return(retVal);
    }