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

Re: Why should I escape ]

Expand Messages
  • douglascrockford
    ... The confusion is with the sequence -]. Does it mean -] or - ]] JSLint is not smart enough to figure that out. Neither are most of us. So code it like you
    Message 1 of 5 , Aug 24, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "altearius" <Nielsen.Chris@...> wrote:
      > > > norm = name.replace(/([\.\/-])/g, '');

      > Can you clarify this? His opening bracket is not escaped, so if he escapes his closing bracket, won't that cause an "unterminated character class" error?
      >
      > It looks like JSLint is reporting one error if this is escaped and a different error if it is not escaped.
      >
      > What is the intended solution here?

      The confusion is with the sequence -]. Does it mean
      \-]
      or
      -\]]

      JSLint is not smart enough to figure that out. Neither are most of us.
      So code it like you mean it.
    • woomla
      ... Changing the sequence to /[- . /]/g gives me Unescaped - . This was the message I was looking for in the first place. I have to escape the - , not the
      Message 2 of 5 , Aug 26, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "douglascrockford" <douglas@...> wrote:
        >
        > The confusion is with the sequence -]. Does it mean
        > \-]
        > or
        > -\]]
        >
        > JSLint is not smart enough to figure that out. Neither are most of us.
        > So code it like you mean it.
        >

        Changing the sequence to /[-\.\/]/g gives me "Unescaped '-'."
        This was the message I was looking for in the first place.
        I have to escape the '-', not the ']'!

        (The '-' can be used to create a set: /[a-z\.\/]/g will replace all characters a through z, the '.' and the '\' character).
      Your message has been successfully submitted and would be delivered to recipients shortly.