Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/java/org/xwiki/rendering/macro/script/RenderingTests.java
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/java/org/xwiki/rendering/macro/script/RenderingTests.java	(revision 29463)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/java/org/xwiki/rendering/macro/script/RenderingTests.java	(working copy)
@@ -39,9 +39,7 @@
 
         suite.addTestsFromResource("macroscript1", true);
         suite.addTestsFromResource("macroscript2", true);
-        suite.addTestsFromResource("macroscript3", true);
         suite.addTestsFromResource("macroscript4", true);
-        suite.addTestsFromResource("macroscript5", true);
 
         ComponentManagerTestSetup testSetup = new ComponentManagerTestSetup(suite);
         new ScriptMockSetup(testSetup.getComponentManager());
Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/resources/macroscript3.test
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/resources/macroscript3.test	(revision 29463)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/resources/macroscript3.test	(working copy)
@@ -1,27 +0,0 @@
-.#-----------------------------------------------------
-.input|xwiki/2.0
-.# Validate that inner macro is transformed also
-.#-----------------------------------------------------
-{{script}}
-{{script}}
-script here
-{{/script}}
-{{/script}}
-.#-----------------------------------------------------
-.expect|event/1.0
-.#-----------------------------------------------------
-beginDocument
-beginMacroMarkerStandalone [script] [] [{{script}}
-script here
-{{/script}}]
-beginMacroMarkerStandalone [script] [] [script here]
-beginParagraph
-onWord [script]
-onSpace
-onWord [here]
-endParagraph
-endMacroMarkerStandalone [script] [] [script here]
-endMacroMarkerStandalone [script] [] [{{script}}
-script here
-{{/script}}]
-endDocument
\ No newline at end of file
Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/resources/macroscript5.test
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/resources/macroscript5.test	(revision 29463)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/test/resources/macroscript5.test	(working copy)
@@ -1,23 +0,0 @@
-.#-----------------------------------------------------
-.input|xwiki/2.0
-.# Validate that inner macro is inline too
-.#-----------------------------------------------------
-text {{script}}{{script}}script here{{/script}}{{/script}} text
-.#-----------------------------------------------------
-.expect|event/1.0
-.#-----------------------------------------------------
-beginDocument
-beginParagraph
-onWord [text]
-onSpace
-beginMacroMarkerInline [script] [] [{{script}}script here{{/script}}]
-beginMacroMarkerInline [script] [] [script here]
-onWord [script]
-onSpace
-onWord [here]
-endMacroMarkerInline [script] [] [script here]
-endMacroMarkerInline [script] [] [{{script}}script here{{/script}}]
-onSpace
-onWord [text]
-endParagraph
-endDocument
\ No newline at end of file
Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/macro/script/ScriptMacro.java
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/macro/script/ScriptMacro.java	(revision 0)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/macro/script/ScriptMacro.java	(revision 0)
@@ -0,0 +1,34 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.macro.script;
+
+
+/**
+ * An interface used to distinguish script macros from the rest. The most important difference
+ * is that script macros cannot be nested.
+ * 
+ * @version $Id$
+ * @since 2.4
+ */
+public interface ScriptMacro
+{
+
+}
+

Property changes on: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/macro/script/ScriptMacro.java
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision HeadURL
Added: svn:eol-style
   + native

Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/macro/script/AbstractScriptMacro.java
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/macro/script/AbstractScriptMacro.java	(revision 29463)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/macro/script/AbstractScriptMacro.java	(working copy)
@@ -20,7 +20,6 @@
 package org.xwiki.rendering.macro.script;
 
 import java.io.StringReader;
-import java.net.URLClassLoader;
 import java.util.Collections;
 import java.util.List;
 
@@ -35,6 +34,7 @@
 import org.xwiki.rendering.block.MacroBlock;
 import org.xwiki.rendering.block.XDOM;
 import org.xwiki.rendering.internal.macro.script.AttachmentClassLoaderFactory;
+import org.xwiki.rendering.internal.macro.script.ScriptMacroUtils;
 import org.xwiki.rendering.macro.AbstractMacro;
 import org.xwiki.rendering.macro.MacroExecutionException;
 import org.xwiki.rendering.macro.descriptor.ContentDescriptor;
@@ -51,6 +51,7 @@
  * @since 1.7M3
  */
 public abstract class AbstractScriptMacro<P extends ScriptMacroParameters> extends AbstractMacro<P>
+    implements ScriptMacro
 {
     /**
      * The default description of the script macro content.
@@ -106,6 +107,12 @@
     private ParserUtils parserUtils = new ParserUtils();
 
     /**
+     * Used to check for nested scripts.
+     */
+    @Requirement
+    private ScriptMacroUtils scriptUtils;
+
+    /**
      * @param macroName the name of the macro (eg "groovy")
      */
     public AbstractScriptMacro(String macroName)
@@ -196,6 +203,11 @@
             try {
                 Thread.currentThread().setContextClassLoader(newClassLoader);
 
+                // 0) Abort execution if the script is nested, XWIKI-5275
+                if (scriptUtils.isScriptNested(context.getCurrentMacroBlock())) {
+                    throw new MacroExecutionException("Nested scripts are not allowed");
+                }
+
                 // 1) Run script engine on macro block content
                 String scriptResult = evaluate(parameters, content, context);
 
@@ -238,7 +250,7 @@
      * @return the class loader to use for executing the script
      * @throws Exception in case of an error in building the class loader
      */
-    private URLClassLoader findClassLoader(String jarsParameterValue, ClassLoader parent) throws Exception
+    private ClassLoader findClassLoader(String jarsParameterValue, ClassLoader parent) throws Exception
     {
         // We cache the Class Loader for improved performances and we check if the saved class loader had the same
         // jar parameters value as the current execution. If not, we compute a new class loader.
Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/ScriptMacroUtils.java
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/ScriptMacroUtils.java	(revision 0)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/ScriptMacroUtils.java	(revision 0)
@@ -0,0 +1,41 @@
+/*
+ *  This file is part of xwiki-core-rendering-macro-script
+ *
+ *  Copyright (c) 2008-2010 Alex Busenius
+ *
+ *  xwiki-core-rendering-macro-script is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  xwiki-core-rendering-macro-script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with xwiki-core-rendering-macro-script.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.xwiki.rendering.internal.macro.script;
+
+import org.xwiki.component.annotation.ComponentRole;
+import org.xwiki.rendering.block.MacroBlock;
+
+/**
+ * An internal component for accessing script macro-related utility methods.
+ * 
+ * @version $Id$
+ * @since 2.4
+ */
+@ComponentRole
+public interface ScriptMacroUtils
+{
+    /**
+     * Check if the given macro block is nested inside a script macro.
+     * 
+     * @param currentBlock the block to check
+     * @return true if the block is a ancestor of a script macro block
+     */
+    boolean isScriptNested(MacroBlock currentBlock);
+}

Property changes on: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/ScriptMacroUtils.java
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision HeadURL
Added: svn:eol-style
   + native

Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/DefaultScriptMacroUtils.java
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/DefaultScriptMacroUtils.java	(revision 0)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/DefaultScriptMacroUtils.java	(revision 0)
@@ -0,0 +1,70 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.xwiki.rendering.internal.macro.script;
+
+import org.xwiki.component.annotation.Component;
+import org.xwiki.component.annotation.Requirement;
+import org.xwiki.rendering.block.MacroBlock;
+import org.xwiki.rendering.block.MacroMarkerBlock;
+import org.xwiki.rendering.macro.MacroId;
+import org.xwiki.rendering.macro.MacroLookupException;
+import org.xwiki.rendering.macro.MacroManager;
+import org.xwiki.rendering.macro.script.ScriptMacro;
+
+/**
+ * A collection of utility methods for script macros.
+ * 
+ * @version $Id$
+ * @since 2.4
+ */
+@Component
+public class DefaultScriptMacroUtils implements ScriptMacroUtils
+{
+    /** Used to get a macro by id. */
+    @Requirement
+    private MacroManager macroManager;
+
+    /**
+     * {@inheritDoc}
+     * @see org.xwiki.rendering.internal.macro.script.ScriptMacroUtils#isScriptNested(org.xwiki.rendering.block.MacroBlock)
+     */
+    public boolean isScriptNested(MacroBlock currentBlock)
+    {
+        // traverse the XDOM tree up to the root
+        MacroMarkerBlock parent = currentBlock.getParentBlockByType(MacroMarkerBlock.class);
+        while (parent != null) {
+            String parentId = parent.getId();
+            try {
+                if (macroManager.getMacro(new MacroId(parentId)) instanceof ScriptMacro) {
+                    return true;
+                } else if ("include".equals(parentId)) {
+                    // included documents intercept the chain of nested script macros with XWiki syntax
+                    return false;
+                }
+            } catch (MacroLookupException exception) {
+                // shouldn't happen, the parent macro was already successfully executed earlier
+                System .out.println("FUCK: " + exception.getMessage());
+                exception.printStackTrace();
+            }
+            parent = parent.getParentBlockByType(MacroMarkerBlock.class);
+        }
+        return false;
+    }
+}

Property changes on: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/java/org/xwiki/rendering/internal/macro/script/DefaultScriptMacroUtils.java
___________________________________________________________________
Added: svn:keywords
   + Author Id Revision HeadURL
Added: svn:eol-style
   + native

Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/resources/META-INF/components.txt
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/resources/META-INF/components.txt	(revision 29463)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-script/src/main/resources/META-INF/components.txt	(working copy)
@@ -1,2 +1,3 @@
 org.xwiki.rendering.internal.macro.script.DefaultScriptMacro
-org.xwiki.rendering.internal.macro.script.DefaultAttachmentClassLoaderFactory
\ No newline at end of file
+org.xwiki.rendering.internal.macro.script.DefaultAttachmentClassLoaderFactory
+org.xwiki.rendering.internal.macro.script.DefaultScriptMacroUtils
\ No newline at end of file
Index: core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/main/java/org/xwiki/rendering/internal/macro/html/HTMLMacro.java
===================================================================
--- core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/main/java/org/xwiki/rendering/internal/macro/html/HTMLMacro.java	(revision 29463)
+++ core/xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-html/src/main/java/org/xwiki/rendering/internal/macro/html/HTMLMacro.java	(working copy)
@@ -249,6 +249,8 @@
             MacroMarkerBlock htmlMacroMarker =
                 new MacroMarkerBlock(htmlMacroBlock.getId(), htmlMacroBlock.getParameters(), htmlMacroBlock
                     .getContent(), xdom.getChildren(), htmlMacroBlock.isInline());
+            // otherwise the HTML block will not be able to access the parent DOM, XWIKI-5275
+            htmlMacroMarker.setParent(htmlMacroBlock.getParent());
 
             // Execute the Macro transformation
             transformation.transform(htmlMacroMarker, context.getTransformationContext());
Index: core/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/transformation/MacroTransformation.java
===================================================================
--- core/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/transformation/MacroTransformation.java	(revision 29463)
+++ core/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/transformation/MacroTransformation.java	(working copy)
@@ -235,10 +235,17 @@
         return macroHolders.size() > 0 ? macroHolders.get(0) : null;
     }
 
+    /**
+     * Wrap the output of a macro block with a {@link MacroMarkerBlock}.
+     * 
+     * @param macroBlockToWrap the block that should be replaced
+     * @param newBlocks list of blocks to wrap
+     * @return the wrapper
+     */
     private Block wrapInMacroMarker(MacroBlock macroBlockToWrap, List<Block> newBlocks)
     {
-        return new MacroMarkerBlock(macroBlockToWrap.getId(), macroBlockToWrap.getParameters(), macroBlockToWrap
-            .getContent(), newBlocks, macroBlockToWrap.isInline());
+        return new MacroMarkerBlock(macroBlockToWrap.getId(), macroBlockToWrap.getParameters(),
+            macroBlockToWrap.getContent(), newBlocks, macroBlockToWrap.isInline());
     }
 
     private void generateError(MacroBlock macroToReplace, String message, String description)
