Grails
  1. Grails
  2. GRAILS-4253

URLMapping stripping .text from the url

    Details

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

      Description

      I have the following UrlMappings entry:
      static mappings = {

      "/lib/$uri**" (controller: 'library', action: 'showContent')
      }

      And in the LibraryController I have:
      def showContent = {
      render "$

      {params.uri}

      "
      }

      If I enter the url:

      /lib/foo.abc

      Then I get foo.abc

      If I enter

      /lib/foo.text

      Then I get foo

      I was expecting foo.text

        Activity

        Hide
        Graeme Rocher added a comment -

        Have you tried setting this to false in grails-app/conf/Config.groovy?:

        grails.mime.file.extensions = false
        
        Show
        Graeme Rocher added a comment - Have you tried setting this to false in grails-app/conf/Config.groovy?: grails.mime.file.extensions = false
        Hide
        Graeme Rocher added a comment -

        Just to elaborate in Config.groovy tthere is this definition:

        grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
                              xml: ['text/xml', 'application/xml'],
                              text: 'text/plain',
        

        Note how "text" is one of the formats that is handled. If you remove "text" from that list your code will work. Alternatiavely you can do this:

        def showContent = {
        render "${params.uri}.${request.format}"
        }
        
        Show
        Graeme Rocher added a comment - Just to elaborate in Config.groovy tthere is this definition: grails.mime.types = [ html: ['text/html','application/xhtml+xml'], xml: ['text/xml', 'application/xml'], text: 'text/plain', Note how "text" is one of the formats that is handled. If you remove "text" from that list your code will work. Alternatiavely you can do this: def showContent = { render "${params.uri}.${request.format}" }
        Hide
        Yan Pujante added a comment -

        I tried to set
        grails.mime.file.extensions = false
        and it indeed resolves the issue.

        My only worry is that it is for the whole application. I think I have a controller which is very specific and needs the full uri unprocessed (which is somewhat expressed by my mapping). But if I have other controllers that need this feature then it won't work.

        Ideally you would want to express it per mapping or per controller.

        I cannot use $

        {params.uri}

        .$

        {request.format}

        because I need to be able to handle anything.

        I understand that this may be a very specific use case... for now I prefer to leave the config unchanged and I use the following workaround:

        private URI extractURI(request)

        { String uri = request.getAttribute("javax.servlet.forward.servlet_path"); uri = uri - "/lib/" return new URI(uri) }

        Not ideal but it works.

        Show
        Yan Pujante added a comment - I tried to set grails.mime.file.extensions = false and it indeed resolves the issue. My only worry is that it is for the whole application. I think I have a controller which is very specific and needs the full uri unprocessed (which is somewhat expressed by my mapping). But if I have other controllers that need this feature then it won't work. Ideally you would want to express it per mapping or per controller. I cannot use $ {params.uri} .$ {request.format} because I need to be able to handle anything. I understand that this may be a very specific use case... for now I prefer to leave the config unchanged and I use the following workaround: private URI extractURI(request) { String uri = request.getAttribute("javax.servlet.forward.servlet_path"); uri = uri - "/lib/" return new URI(uri) } Not ideal but it works.
        Hide
        Graeme Rocher added a comment -

        Ok we'll see if we can make it configurable per mapping, btw for your code above you can also use:

        String uri = request.forwardURI
        
        Show
        Graeme Rocher added a comment - Ok we'll see if we can make it configurable per mapping, btw for your code above you can also use: String uri = request.forwardURI
        Hide
        Graeme Rocher added a comment -

        There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3

        for 1.2 final only issues considered blocking will now be fixed

        Show
        Graeme Rocher added a comment - There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3 for 1.2 final only issues considered blocking will now be fixed

          People

          • Assignee:
            Unassigned
            Reporter:
            Yan Pujante
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Last Reviewed:

              Development