Grails
  1. Grails
  2. GRAILS-5772

Calling createTemplate(String code, String name) can result in exceptions on windows systems if name contains illegal filesystem chars

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.2 final
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      We had a Weceem user experiencing problems with 0.9-snapshot of weceem with grails 1.2 on windows.

      Our code calls the GroovyPagesTemplateEngine.createTemplate(code, pageName) method - passing in a URI as the pageName. There's nothing in the contract that says page name must be a valid filesystem file path - but if it is not, eg contains "/" on Windows systems, you get exceptions:

      org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: I/O parsing Groovy page [Content:templates/default-template]: Syntaksen i filnavnet, mappen eller diskenhedsnavnet er forkert
      at org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine.buildPageMetaInfo(GroovyPagesTemplateEngine.java:538)
      at org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine.createTemplate(GroovyPagesTemplateEngine.java:411)
      at org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine.createTemplate(GroovyPagesTemplateEngine.java:325)
      at org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine.createTemplate(GroovyPagesTemplateEngine.java:319)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
      at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)
      at org.weceem.services.ContentRepositoryService$_getGSPTemplate_closure4.doCall(ContentRepositoryService.groovy:245)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:225)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:151)
      at org.weceem.services.ContentRepositoryService$_getGSPTemplate_closure4.doCall(ContentRepositoryService.groovy)

      This is because of this code in GroovyPagesTemplateEngine:

      >>> grails/src/java/org/codehaus/groovy/grails/web/pages/GroovyPagesTemplateEngine.java
      
          public Template createTemplate(String txt, String pageName) throws IOException {
              if(StringUtils.isBlank(txt)) throw new IllegalArgumentException("Argument [txt] cannot be null or blank");
              if(StringUtils.isBlank(pageName)) throw new IllegalArgumentException("Argument [pageName] cannot be null or blank");
              
              return createTemplate(new ByteArrayResource(txt.getBytes("UTF-8"), pageName), pageName);
          }
       
          private Template createTemplate(Resource resource, String pageName) throws IOException {
              InputStream in = resource.getInputStream();
              try {
                  return createTemplate(in, resource, pageName);
              }
              finally {
                 in.close();
              }
          }
       
      

      So basically this creates the ByteArrayResource with the name we pages in, and later in buildPageMetaInfo this crashes and burns:

              GroovyPageParser parser;
              String path = getPathForResource(res);
              try {
                  parser = new GroovyPageParser(name, path, path, inputStream);
              } catch (IOException e) {
                  throw new GroovyPagesException("I/O parsing Groovy page ["+(res != null ? res.getDescription() : name)+"]: " + e.getMessage(),e);
              }
              InputStream in = parser.parse();
      

      Now, it seems to me the real bug is probably that the parser should not even be trying to access this "file" as it doesn't exist at all.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Marc Palmer
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Last Reviewed:

              Development