Results 1 to 4 of 4

Thread: String escaping in Grails GSP

  1. #1
    Join Date
    Jul 2011
    Posts
    8

    Default String escaping in Grails GSP

    Hello, I've come across a problem, I'm trying to pass in a regular expression to a taglib as a string, and I need to include some groups in the regex, which requires the [ and ] characters.

    However when I try to insert them in my gsp file, they are seen as starting a list or map and throw an error.

    I tried using ' instead of " and even slashy strings, but none worked.

    Heres an example of what I'm talking about:

    Code:
    <g:tag pattern="/[A-z]{2}/" />
    The [ starts a list and I can't seem to escape it which causes an error in the IDE and disallows building/running, I put a \ infront of it and nothing.
    Any suggestions?
    The IDE i'm using is IntelliJ IDEA 9 Ultimate.

  2. #2
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    It seems to work fine if you don't have the '/' characters in there.

  3. #3
    Join Date
    Jul 2011
    Posts
    8

    Default

    are you using an IDE or just the command line?

  4. #4
    Join Date
    Jul 2011
    Posts
    8

    Default

    I've come up with a few solutions to get the IDE to stop seeing it as an error.

    1: Inject it with Groovy using <%%> tags
    Ala:
    Code:
    <% def pattern = /patternhere/ %>
    <g:tag pattern="${pattern}"/>
    That works fine.

    2: Fake it out with an empty injection.
    Code:
    <g:tag pattern="${''}[A-z]{2}" />
    works fine too and doesn't error for some reason.

    I'm probably going with solution 2 for now, just to cut down on number of lines.
    Maybe IDEA 10 fixed this issue, at least it's not a GRAILS / GROOVY bug

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •