Skip to content

Commit

Permalink
Merge pull request #22 from 2sic/develop
Browse files Browse the repository at this point in the history
bugfix
  • Loading branch information
iJungleboy authored Jun 30, 2022
2 parents 6713ba5 + 2dec147 commit 03c30cb
Show file tree
Hide file tree
Showing 128 changed files with 1,566 additions and 1,168 deletions.
55 changes: 32 additions & 23 deletions Razor.Blade/Markup/ChildTags.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static ToSic.Razor.Markup.ToHtmlHybridBase;

namespace ToSic.Razor.Markup
{
public class ChildTags: List<TagBase>
{
public void Add(object child)
public void Add(params object[] children)
{
// Untangle deeper objects if necessary
// This is because child could be
// - a single item
// - an array of items - like a string[]
// - an array with a single item - which itself is an ienumerable

// Handle null, string, or single TagBase object
if (AddOrSkipNullOrTagBase(child)) return;
var child = children;

// Check for IEnumerable, but make sure we don't pick up strings
// This doesn't process it yet, just ensures that in case it's an array/list of real items, that it is unwrapped
if (!(child is string) && child is IEnumerable childEnum)
{
var tempList = childEnum.Cast<object>().ToList();
if (!tempList.Any()) return;

// If it has exactly one item, it's probably an array/enumerable in an array, so unwrap
if (tempList.Count == 1)
{
child = tempList.First();
// Handle null, string, or single TagBase object
if (AddOrSkipNullOrTagBase(child)) return;
}
}
// 2022-06-29 v3.14 - shouldn't be used any more, as it's always an array now
//// Handle null, string, or single TagBase object
//if (AddOrSkipNullOrTagBase(child)) return;

// 1. Check for IEnumerable, but make sure we don't pick up strings

//// This doesn't process it yet, just ensures that in case it's an array/list of real items, that it is unwrapped
//if (!(child is string) && child is IEnumerable childEnum)
//{
// var tempList = childEnum.Cast<object>().ToList();
// if (!tempList.Any()) return;

// // If it has exactly one item, it's probably an array/enumerable in an array, so unwrap
// if (tempList.Count == 1)
// {
// // Changes the 'child' for further processing if it's an accidental array which itself contains 1 IEnumerable<TagBase> for later on
// child = tempList.First();
// // Handle null, string, or single TagBase object
// if (AddOrSkipNullOrTagBase(child)) return;
// }
//}


// 2. Import a TagBase list
// if it's a classic tag list - everything is ok
// This could also be the result of processing #1 before
if (child is IEnumerable<TagBase> list)
{
AddRange(list);
Expand All @@ -43,7 +51,8 @@ public void Add(object child)

// otherwise check if it's a list, but exclude strings,
// because otherwise it will try to enumerate each character
if(!(child is string) && child is IEnumerable nonTagList)
// 2022-06-29 v3.14 - shouldn't be used any more, as it's always an array now
if (/*!(child is string) &&*/ child is IEnumerable nonTagList)
{
foreach (var item in nonTagList)
base.Add(TagBase.EnsureTag(item));
Expand All @@ -66,19 +75,19 @@ private bool AddOrSkipNullOrTagBase(object child)
return true;
}

if (child is string)
if (IsStringOrHtmlString(child, out var childString))
{
base.Add(TagBase.EnsureTag(child));
base.Add(TagBase.EnsureTag(childString));
return true;
}

return false;
}

public void Replace(object child)
public void Replace(params object[] children)
{
Clear();
Add(child);
Add(children);
}

internal string Build(TagOptions options)
Expand Down
46 changes: 23 additions & 23 deletions Razor.Blade/Markup/Tag/Tag.T.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected Tag(string name = null, TagOptions options = null)
: base(name, options) { }

protected Tag(string name, object content, TagOptions options = null)
: base(name, content, options) { }
: base(name, options, content) { }

protected Tag(string name, TagOptions options, object[] content)
: base(name, options, content) { }
Expand Down Expand Up @@ -96,18 +96,18 @@ public T On(string name, object value = null)
=> Attr("on" + name, value, null);


/// <summary>
/// Add contents to this tag - at the end of the already added contents.
/// If you want to replace the contents, use Wrap() instead
/// </summary>
///// <summary>
///// Add contents to this tag - at the end of the already added contents.
///// If you want to replace the contents, use Wrap() instead
///// </summary>

/// <param name="child"></param>
/// <returns></returns>
public T Add(object child)
{
TagChildren.Add(child);
return this as T;
}
///// <param name="child"></param>
///// <returns></returns>
//public T Add(object child)
//{
// TagChildren.Add(child);
// return this as T;
//}

/// <summary>
/// Add contents to this tag - at the end of the already added contents.
Expand All @@ -122,17 +122,17 @@ public T Add(params object[] children)
return this as T;
}

/// <summary>
/// Wrap the tag around the new content, so this replaces all the content with what you give it
/// </summary>

/// <param name="content">New content - can be a string, TagBase or list of tags</param>
/// <returns></returns>
public T Wrap(object content)
{
TagChildren.Replace(content);
return this as T;
}
///// <summary>
///// Wrap the tag around the new content, so this replaces all the content with what you give it
///// </summary>

///// <param name="content">New content - can be a string, TagBase or list of tags</param>
///// <returns></returns>
//public T Wrap(object content)
//{
// TagChildren.Replace(content);
// return this as T;
//}

/// <summary>
/// Wrap the tag around the new content, so this replaces all the content with what you give it
Expand Down
25 changes: 9 additions & 16 deletions Razor.Blade/Markup/Tag/TagBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ protected internal TagBase(string name = null, TagOptions options = null)
TagName = name;
}

protected internal TagBase(string name, object content, TagOptions options = null)
: this(name, options)
{
if (content != null)
TagChildren.Replace(content);
}
//protected internal TagBase(string name, object content, TagOptions options = null) : this(name, options)
//{
// if (content != null)
// TagChildren.Replace(content);
//}

protected internal TagBase(string name, TagOptions options, object[] content) : this(name, options)
protected internal TagBase(string name, TagOptions options, params object[] content) : this(name, options)
{
if(content?.Length > 0)
TagChildren.Replace(content);
Expand Down Expand Up @@ -53,15 +52,9 @@ internal static TagBase Text(string text)
/// <returns></returns>
internal static TagBase EnsureTag(object child)
{
switch (child)
{
case string text:
return Text(text);
case TagBase tag:
return tag;
default:
return new TagBase();
}
if (IsStringOrHtmlString(child, out var s)) return Text(s);
if (child is TagBase tag) return tag;
return new TagBase();
}

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions Razor.Blade/Markup/ToHtmlHybridBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,25 @@ public void WriteTo(System.IO.TextWriter writer, HtmlEncoder encoder)
writer.Write(ToString());
}
#endif

public static bool IsStringOrHtmlString(object original, out string asString)
{
asString = null;
if (original is null) return false;
if (original is string strOriginal)
{
asString = strOriginal;
return true;
}

if (original is IHtmlString)
{
asString = original.ToString();
return true;
}

return false;
}
}

}
2 changes: 1 addition & 1 deletion Razor.Blade/Razor.Blade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net472;net5.0</TargetFrameworks>
<RootNamespace>ToSic.Razor</RootNamespace>
<Version>03.13.00</Version>
<Version>03.14.00</Version>
<AssemblyName>ToSic.Razor</AssemblyName>
<PackageId>ToSic.Razor</PackageId>
<Authors>ToSic.Razor</Authors>
Expand Down
2 changes: 2 additions & 0 deletions Razor.Blade/Wip/XssPrevention.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using ToSic.Razor.Internals;
using ToSic.Razor.Internals.Documentation;

namespace ToSic.Razor.Wip
{
Expand All @@ -8,6 +9,7 @@ namespace ToSic.Razor.Wip
/// https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html
/// https://cheatsheetseries.owasp.org/cheatsheets/DotNet_Security_Cheat_Sheet.html#a7-cross-site-scripting-xss
/// </summary>
[PrivateApi]
public class XssPrevention
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ToSic.Razor.Dnn/ToSic_Razor_Blade_Dnn.dnn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="ToSic.RazorBlade" type="Library" version="03.13.00">
<package name="ToSic.RazorBlade" type="Library" version="03.14.00">
<friendlyName>2sic RazorBlade</friendlyName>
<description>2sic RazorBlade</description>
<iconFile>icon.png</iconFile>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.A.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;A&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;A&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;A&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;A&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;A&gt;.Wrap(Object[])</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.Abbr.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;Abbr&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;Abbr&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;Abbr&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;Abbr&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;Abbr&gt;.Wrap(Object[])</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.Address.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;Address&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;Address&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;Address&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;Address&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;Address&gt;.Wrap(Object[])</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.Area.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;Area&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;Area&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;Area&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;Area&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;Area&gt;.Wrap(Object[])</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.Article.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;Article&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;Article&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;Article&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;Article&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;Article&gt;.Wrap(Object[])</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.Aside.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;Aside&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;Aside&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;Aside&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;Aside&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;Aside&gt;.Wrap(Object[])</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.Audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;Audio&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;Audio&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;Audio&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;Audio&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;Audio&gt;.Wrap(Object[])</a>
</div>
Expand Down
6 changes: 0 additions & 6 deletions docs/api/ToSic.Razor.Html5.B.html
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,9 @@ <h5>Inherited Members</h5>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_On_System_String_System_Object_">Tag&lt;B&gt;.On(String, Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object_">Tag&lt;B&gt;.Add(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Add_System_Object___">Tag&lt;B&gt;.Add(Object[])</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object_">Tag&lt;B&gt;.Wrap(Object)</a>
</div>
<div>
<a class="xref" href="ToSic.Razor.Markup.Tag-1.html#ToSic_Razor_Markup_Tag_1_Wrap_System_Object___">Tag&lt;B&gt;.Wrap(Object[])</a>
</div>
Expand Down
Loading

0 comments on commit 03c30cb

Please sign in to comment.