U4-7462 - Macro with multiline textfield property cannot be inserted in RTE if there are multiple lines of text

Created by Dennis Milandt 26 Nov 2015, 11:02:52 Updated by Sebastiaan Janssen 05 Jan 2016, 09:49:01

Is duplicated by: U4-7533

I created a macro with a textarea property. When inserting it into the RTE it would disappear after saving, if the textarea contained more than one line of text. A HTML comment remained in the HTML afterwards, but the macro and the div surrounding it was gone.

1 Attachments

Download macro bug.mp4


Tommy Enger 27 Nov 2015, 22:17:14

Could this be a duplicate of this one: http://issues.umbraco.org/issue/U4-6206 ?

Dennis Milandt 29 Nov 2015, 13:03:56

Hi Tommy. No, I don't think it is a duplicate. In http://issues.umbraco.org/issue/U4-6206 the example is a Gallery macro with a Multiple media picker property. The issue I am experiencing is only when a Textbox property is added, and only when the property data contains line breaks.

Tommy Enger 29 Nov 2015, 16:01:23

Ok, I'm fixing some other minor bugs on macros, so I could look at this at the same time. But I'm not able to reproduce based on the description. In the description you write textarea and in the comment you write textbox, is it both? Do you put the RTE inside a grid, then add the macro? Or is the RTE a property on the doc type? Or both? All browsers? Does it make a difference if you check/uncheck "Render in the rich text editor and grid"?

Tommy Enger 29 Nov 2015, 17:33:13

Manged to reproduce in RTE-property directly on document type. Works in grids.

Dennis Milandt 29 Nov 2015, 17:43:42

Sorry about the confusion. I mean the multiline textarea. When You add that as a property to a macro, and insert the macro in the rich text editor, and then add some text to the textarea property containing a line break, the macro disappears after saving the page.

I tested in Chrome v. 46 and Internet Explorer 11.

It doesn't make a difference if I check Render in the rich text editor and grid.

Dennis Milandt 29 Nov 2015, 17:49:21

See attached video of the error.

Tommy Enger 30 Nov 2015, 20:20:47

Had a look at this, and it seems like the problem sits in a regex-match in MacroTagParser.cs. The value is stored OK to the database. When getting the value back from the database, and prepare it for the editor, it runs the value through a regex match, and when the value has line breaks, it does not match.

The regex is very sweet and looks like this: (<?UMBRACO_MACRO (?:.+?)?macroAlias=""'[""'].+?)(?:/>|>.*?</?UMBRACO_MACRO>)

I have created a small console app for debugging. If you run the code, you can see that it only gets one match. If you change "test1\n\ntest2" to just "test1test2" you will get 2 matches.

So if we could get a RegEx-Ninja to get 2 matches from the original input, I think we are pretty close to solving this one.

Console app: using System; using System.Text.RegularExpressions;

namespace RegExTest { public class Program { public static void Main(string[] args) { var pattern = new Regex(@"(<?UMBRACO_MACRO (?:.+?)?macroAlias=""'[""'].+?)(?:/>|>.*?</?UMBRACO_MACRO>)", RegexOptions.Compiled | RegexOptions.IgnoreCase); var input = "<?UMBRACO_MACRO macroAlias="macrowithtextarea" text="test1\n\ntest2" /> \n <?UMBRACO_MACRO macroAlias="macrowithtextarea" text="test3" />";

        var match = pattern.Matches(input);

        foreach (Match m in match)
            Console.WriteLine("1:        {0}", m.Groups[0].Value);
            Console.WriteLine("2:        {0}", m.Groups[1].Value);
            Console.WriteLine("3:        {0}", m.Groups[2].Value);



Rasmus Pedersen 14 Dec 2015, 12:54:21

Pull request here https://github.com/umbraco/Umbraco-CMS/pull/947

Priority: Normal

Type: Bug

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted: Pull request

Affected versions: 7.3.1

Due in version: 7.4.0, 7.3.5

Sprint: Sprint 5

Story Points: