-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request from GHSA-gvpc-3pj6-4m9w
* Bump version * Add new MarkDownPropertyValueEditor.cs * Pass attribute to property value editor * Only use ToString() once * Implement own markdown sanitizer instead of using IHtmlSanitizer * Fix comment * Dont use file scoped namespaces --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk>
- Loading branch information
Showing
7 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Umbraco.Core.Security | ||
{ | ||
public interface IMarkdownSanitizer | ||
{ | ||
/// <summary> | ||
/// Sanitizes Markdown | ||
/// </summary> | ||
/// <param name="markdown">Markdown to be sanitized</param> | ||
/// <returns>Sanitized Markdown</returns> | ||
string Sanitize(string markdown); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Umbraco.Core.Security | ||
{ | ||
public class NoopMarkdownSanitizer : IMarkdownSanitizer | ||
{ | ||
public string Sanitize(string markdown) | ||
{ | ||
return markdown; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Umbraco.Web/PropertyEditors/MarkDownPropertyValueEditor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Umbraco.Core; | ||
using Umbraco.Core.Models.Editors; | ||
using Umbraco.Core.PropertyEditors; | ||
using Umbraco.Core.Security; | ||
|
||
namespace Umbraco.Web.PropertyEditors; | ||
|
||
internal class MarkDownPropertyValueEditor : DataValueEditor | ||
{ | ||
private readonly IMarkdownSanitizer _markdownSanitizer; | ||
|
||
public MarkDownPropertyValueEditor(DataEditorAttribute attribute, IMarkdownSanitizer markdownSanitizer) : base(attribute) | ||
{ | ||
_markdownSanitizer = markdownSanitizer; | ||
} | ||
|
||
public override object FromEditor(ContentPropertyData editorValue, object currentValue) | ||
{ | ||
var editorValueString = editorValue.Value?.ToString(); | ||
if (string.IsNullOrWhiteSpace(editorValueString)) | ||
{ | ||
return null; | ||
} | ||
|
||
var sanitized = _markdownSanitizer.Sanitize(editorValueString); | ||
|
||
return sanitized.NullOrWhiteSpaceAsNull(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters