see below
On Tue, Aug 5, 2008 at 5:09 PM, Vincent Massol <vincent(a)massol.net> wrote:
Hi Pascal,
Let's analyse the way it currently works in the new rendering. Let's
take velocity first:
{{velocity}}
... velocity code here...
{{include document="..."/}}
... velocity code here...
{{/velocity}}
These are the steps that are executed:
1/ The whole text is parsed using the wiki syntax parser. This
generates an XDOM object containing a single MacroBlock wrapping the
velocity macro.
2/ When it's rendered, the Macroblock executes, finds the velocity
macro and executes it.
3/ velocity is run on the part inside the velocity macro.
4/ the wiki syntax parser is then executed on the part on which
velocity has been executed. This means that the macros inside the
velocity block are now executed. This means the include macro is
executed. If it contains velocity code it'll be parsed as a standard
paragraph text and all special characters are escaped. So if you have
velocity script in the document you're including for example it'll be
displayed as is without being executed. You'd need to have the
velocity macro wrapping it in the document to include for it to be
executed.
Thus I don't think we have any security issue here.
Now let's look at groovy. The macro is not written yet but I think
it'll work like what is described below. First the following is NOT
valid:
{{groovy}}
... groovy code here...
{{include document="..."/}}
... groovy code here...
{{/velocity}}
Groovy will execute on the part inside the groovy macro and will fail
on the {{include}} part I think since it's not valid groovy syntax.
I agree
Now the groovy code could do something like out.println("{{include
document='...'/}}")
In this case the resulting macro will get executed (since the logic is
that the new rendering uses the MacroTransformation to execute the
macros and this transformation continues to execute till there's no
more macro to execute).
Now if the included document contains groovy code not inside a groovy
macro nothing will happen and the code will be printed as standard
text (no groovy execution). If it's inside a groovy macro then it'll
get executed but only once since the groovy macro in the page doing
the include will have already executed.
To summarize, I think the fact that outside macros execute before
nested macros prevents dangerous things to happen in general. Now I
haven't analysed all cases yet so if you see something dangerous
please let me know so that I can fix it while it's possible.
So you think this might no be dangerous to use include for groovy?
To answer your question Pascal, you would write:
{{groovy}}
... some groovy code...
{{/groovy}}
{{include document="... page containing a groovy macro..."
context="current"/}}
Let me know if I missed something.
I have a question: if you create a groovy object in the first {{groovy}},
could you use it also in the {{include}} (if it basically contains also
{{groovy}} script) since you include the doc in current context?
I mean: are these 2 completely different groovy executions or do they share
the same execution context?
br
Pascal
Thanks
-Vincent
On Aug 5, 2008, at 9:36 AM, Pascal Voitot wrote:
Hello,
Do you foresee a special syntax for groovy scripts as you already
have for
velocity using {{velocity}} with some more features?
My idea is to be able to code cleanly using groovy and to put some
"generic"
part of scripts in separated documents and to be able to import them
in
other docs containing other parts of scripts.
It would be really nice to be able to type some part of scripts or
to define
some groovy classes in a page and tell "this is groovy code which is
not
"WIKI-renderable" as is".
Then we could simply import/include this script in another page
(just paste
the code without any rendering) using something like
#include("MySpace.MyGroovyDoc").
xwiki.parseGroovyXXX is useful sometimes but not when you only want to
include some part of scripts.
Existing #includeXXX macros always render the content and here I
only want
to paste a script from somewhere else
(xwiki.getDocument("").getContent() in
fact)
Moreover the idea would be also to allow using both
"xwiki.parseGroovy" and
the #include macro for the same groovy "document". For the time
being, one
need to use the trick
/* groovygroovy #* */
/* *# */
and then you are condemned to use xwiki.parseGroovyXXX because no
other
function can interprete this tricky syntax.
best regards
Pascal
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs