@@ -131,10 +131,14 @@ private static Object evaluate(
131131 throw new TemplateProcessingException ("Expression content is null, which is not allowed" );
132132 }
133133
134- final ComputedOGNLExpression parsedExpression ;
134+ ComputedOGNLExpression parsedExpression ;
135135 try {
136136 parsedExpression =
137137 obtainComputedOGNLExpression (configuration , expression , exp , expContext , applyOGNLShortcuts );
138+ if (parsedExpression .isShortcut ()
139+ && (expContext .getRestrictVariableAccess () || expContext .getRestrictExternalAccess ())) {
140+ parsedExpression = parsedExpression .getNonShortcutExpression (exp );
141+ }
138142 } catch (final OgnlException e ) {
139143 throw new TemplateProcessingException (
140144 "Exception evaluating OGNL expression: \" " + expression .getExpression () + "\" " , e );
@@ -420,13 +424,27 @@ private static final class ComputedOGNLExpression {
420424
421425 final Object expression ;
422426 final boolean mightNeedExpressionObjects ;
427+ private volatile ComputedOGNLExpression nonShortcutExpression = null ;
423428
424429 ComputedOGNLExpression (final Object expression , final boolean mightNeedExpressionObjects ) {
425430 super ();
426431 this .expression = expression ;
427432 this .mightNeedExpressionObjects = mightNeedExpressionObjects ;
428433 }
429434
435+ boolean isShortcut () {
436+ return this .expression instanceof OGNLShortcutExpression ;
437+ }
438+
439+ ComputedOGNLExpression getNonShortcutExpression (final String exp ) throws OgnlException {
440+ ComputedOGNLExpression computedExpression = this .nonShortcutExpression ;
441+ if (computedExpression == null ) {
442+ computedExpression = parseExpression (exp , false );
443+ this .nonShortcutExpression = computedExpression ;
444+ }
445+ return computedExpression ;
446+ }
447+
430448
431449 }
432450
0 commit comments