diff options
author | Claude Brisson <cbrisson@apache.org> | 2020-01-24 07:45:06 +0000 |
---|---|---|
committer | Claude Brisson <cbrisson@apache.org> | 2020-01-24 07:45:06 +0000 |
commit | 20ea45c4884a358ec40273df1b3f5dd69ac0aae1 (patch) | |
tree | f5f7235de501a26c37ff9e04c0c6baef5da5b724 /velocity-engine-core | |
parent | bf33425e64cb59b0f69ef60296f5fde84dfd9558 (diff) | |
download | apache-velocity-engine-20ea45c4884a358ec40273df1b3f5dd69ac0aae1.tar.gz |
[engine][VELOCITY-925] Fix BC whitespace gobbling for macro call without parentheses
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1873088 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core')
6 files changed, 37 insertions, 3 deletions
diff --git a/velocity-engine-core/src/main/parser/Parser.jjt b/velocity-engine-core/src/main/parser/Parser.jjt index 40517869..df5748d7 100644 --- a/velocity-engine-core/src/main/parser/Parser.jjt +++ b/velocity-engine-core/src/main/parser/Parser.jjt @@ -1781,6 +1781,7 @@ boolean Directive(boolean afterNewline) : ArrayList argtypes = new ArrayList(4); String blockPrefix = ""; ASTBlock block = null, elseBlock = null; + boolean hasParentheses = false; boolean newlineAtStart = afterNewline; } { @@ -1908,6 +1909,7 @@ boolean Directive(boolean afterNewline) : <SINGLE_LINE_COMMENT_START> [<SINGLE_LINE_COMMENT>] ) )* (<WHITESPACE> | <NEWLINE>)* <RPAREN> + { hasParentheses = true; } ) | { @@ -1918,10 +1920,10 @@ boolean Directive(boolean afterNewline) : [ // Conditions where whitespace and newline postfix is eaten by space gobbling at this point: // - block directive - // - new line before directive - // - backward compatibility mode + // - new line before directive without backward compatibility mode + // - backward compatibility mode *with parentheses* // - #include() or #parse() - LOOKAHEAD(2, { directiveType != Directive.LINE || newlineAtStart || rsvc.getSpaceGobbling() == SpaceGobbling.BC || d != null && (d instanceof Include || d instanceof Parse) }) + LOOKAHEAD(2, { directiveType != Directive.LINE || newlineAtStart && rsvc.getSpaceGobbling() != SpaceGobbling.BC || rsvc.getSpaceGobbling() == SpaceGobbling.BC && hasParentheses || d != null && (d instanceof Include || d instanceof Parse) }) ( [ ( t = <WHITESPACE> ) ] ( u = <NEWLINE> ) ) { afterNewline = true; diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.BC b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.BC new file mode 100644 index 00000000..b9dd4b84 --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.BC @@ -0,0 +1,6 @@ +----- +value +----- + +----- +value----- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.LINES b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.LINES new file mode 100644 index 00000000..856047a4 --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.LINES @@ -0,0 +1,5 @@ +----- +value----- + +----- +value----- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.NONE b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.NONE new file mode 100644 index 00000000..e66cde7a --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.NONE @@ -0,0 +1,8 @@ + +----- +value +----- + +----- +value +----- diff --git a/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.STRUCTURED b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.STRUCTURED new file mode 100644 index 00000000..856047a4 --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/compare/macro2.vtl.STRUCTURED @@ -0,0 +1,5 @@ +----- +value----- + +----- +value----- diff --git a/velocity-engine-core/src/test/resources/gobbling/macro2.vtl b/velocity-engine-core/src/test/resources/gobbling/macro2.vtl new file mode 100644 index 00000000..3d9f7da1 --- /dev/null +++ b/velocity-engine-core/src/test/resources/gobbling/macro2.vtl @@ -0,0 +1,8 @@ +#macro(test)value#end +----- +#test +----- + +----- +#test() +----- |