Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-927

Parsing problem with space before closing curly bracket

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.2
    • 2.3
    • Engine
    • None

    Description

      After updateing from a slightly outdated velocity 1.x to 2.x wo have some issues with our existing templates.

      Some of them are already fixed in 2.2 but at least for now we still have one issue.

      This template

          #set ( $nameMap10 =
          {
          })

      results in 

      org.apache.velocity.runtime.parser.TemplateParseException: Encountered "}" at test[line 3, column 5]
      Was expecting one of:
          "[" ...
          "{" ...
          <WHITESPACE> ...
          <NEWLINE> ...
          <STRING_LITERAL> ...
          "true" ...
          "false" ...
          <INTEGER_LITERAL> ...
          <FLOATING_POINT_LITERAL> ...
          <IDENTIFIER> ...
          <OLD_IDENTIFIER> ...
          "{" ...
          "[" ...
      

      it seems that the whitespaces and newlines in this example matter.

      Modifying the tempalte to

          #set ( $nameMap10 =
          {})
      

      seems to workaround this issue but it would be nice if this would be fixed in Velocity.

       

      Here is a small test-case:

        @Test
        public void testEmptyMap()
          throws Exception
        {
          final String _empty_map = new StringBuilder()
              .append("    #set ( $nameMap10 =\n")
              .append("    {\n")
              .append("    })\n")
              .toString();
            final Template _template = new Template();
            _template.setRuntimeServices(RuntimeSingleton.getRuntimeServices());
            _template.setEncoding(ModuleManager.getInstance().getDefaultEncoding());
            _template.setName("test");
            _template.setData(RuntimeSingleton.getRuntimeServices().parse(new StringReader(_empty_map.toString()), _template));
            _template.initDocument();
            final VelocityContext _context = new VelocityContext();
            _template.merge(_context, new StringWriter());
        }
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            cbrisson Claude Brisson
            AlBundy33 Al Bundy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment