Loading ...
Sorry, an error occurred while loading the content.

1589[jslint] Re: Bad escapement.

Expand Messages
  • pauanyu
    Nov 13, 2010
      --- In jslint_com@yahoogroups.com, "Cheney, Edward A SSG RES USAR USARC" <austin.cheney@...> wrote:
      > > Try this regular expression:
      > >
      > > /url\(((?:[^\)\\]|\\.)*)\)/
      > >
      > > You would use it like so:
      > >
      > > string.replace(regexp, "url(\"$1\")");
      > >
      > There are some problems with that.
      > 1) The regexp does not account for the prior existence of single or double quote characters that may or may not be applied in a valid manner.

      Correct. I attempted to do that with a regular expression, and I'm not sure if it's even possible. Additional logic will likely be required to check for already-existing quotes.

      > 2) The regexp does not appear to be accounting for open parenthesis with or without proper escapement.

      With the above regular expression, the following would match:



      It could probably be changed to make the above invalid.

      > 3) There are many characters that have valid syntax representation in URI and like wise have valid syntax representation in CSS. These characters have to be accounted for in a manner that is not conflicting with CSS syntax and simultaneously does not alter their application in a URI instance.

      The above expression matches any character except a non-escaped ). That means, that it is extremely liberal in what it accepts. If you want it to be stricter, that would be possible as well, though it would require more work. Thus, this is valid (as it should be):


      > As a result I have chosen to use regexp to escape certain necessary characters into an arbitrary string and perform the next stages of processing using standard string methods in a loop.

      That is fine, just be careful because it is possible (albeit very unlikely) for your arbitrary string to be found in the URI.
    • Show all 5 messages in this topic