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

Parsing problem with space before closing curly bracket

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.3
    • Component/s: Engine
    • Labels:
      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

            People

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

              Dates

              • Created:
                Updated:
                Resolved: