package de.agilecoders.wicket.jquery.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

/**
 * tests the {@link de.agilecoders.wicket.jquery.util.Strings2} class
 *
 * @author miha
 */
public class Strings2Test {

	@Test
	public void escapeCharacters() {
		assertThat(
				Strings2.escapeMarkupId("!\"#$%&'()*+,./:;<=>?@[\\]^`{|}~").toString(),
				is("\\\\!\\\\\"\\\\#\\\\$\\\\%\\\\&\\\\'\\\\(\\\\)\\\\*\\\\+\\\\,\\\\.\\\\/\\\\:\\\\;\\\\<\\\\=\\\\>\\\\?\\\\@\\\\[\\\\\\\\\\]\\\\^\\\\`\\\\{\\\\|\\\\}\\\\~"));

		assertThat(Strings2.escapeMarkupId("my.custom.markup-id").toString(), is("my\\\\.custom\\\\.markup-id"));
	}

}

@@ -37,16 +37,40 @@
 .util;%0A%0A
+import org.junit.Test;%0A%0A
 import s
@@ -163,32 +163,8 @@
 t;%0A%0A
-import org.junit.Test;%0A%0A
 /**%0A
@@ -289,16 +289,22 @@
  %7B%0A%0A
-%09
+    
 @Test%0A
-%09
+    
 publ
@@ -332,18 +332,24 @@
 ers() %7B%0A
-%09%09
+        
 assertTh
@@ -351,21 +351,16 @@
 ertThat(
-%0A%09%09%09%09
 Strings2
@@ -427,124 +427,95 @@
 (),%0A
-%09%09%09%09is(%22%5C%5C%5C%5C!%5C%5C%5C%5C%5C%22%5C%5C%5C%5C#%5C%5C%5C%5C$%5C%5C
+                   is(%22%5C%5C!%5C%5C%5C%22%5C%5C#%5C%5C$
 %5C%5C%25%5C%5C
-%5C%5C
 &%5C%5C
-%5C%5C'%5C%5C%5C%5C(%5C%5C%5C%5C)%5C%5C%5C%5C*%5C%5C%5C%5C+%5C%5C%5C%5C,%5C%5C%5C%5C.%5C%5C
+'%5C%5C(%5C%5C)%5C%5C*%5C%5C+%5C%5C,%5C%5C.
 %5C%5C/%5C%5C
-%5C%5C
 :%5C%5C
-%5C%5C;%5C%5C%5C%5C%3C%5C%5C%5C%5C=%5C%5C
+;%5C%5C%3C%5C%5C=
 %5C%5C%3E%5C%5C
-%5C%5C
 ?%5C%5C
-%5C%5C@%5C%5C
+@
 %5C%5C%5B%5C
@@ -523,51 +523,41 @@
 %5C%5C%5C%5C
-%5C%5C%5C%5C%5D%5C%5C%5C%5C%5E%5C%5C%5C%5C%60%5C%5C%5C%5C%7B%5C%5C
+%5D%5C%5C%5E%5C%5C%60%5C%5C%7B
 %5C%5C%7C%5C%5C
-%5C%5C
 %7D%5C%5C
-%5C%5C
 ~%22));%0A%0A
-%09%09
+        
 asse
@@ -621,16 +621,35 @@
 tring(),
+%0A                  
  is(%22my%5C
@@ -649,18 +649,16 @@
 is(%22my%5C%5C
-%5C%5C
 .custom%5C
@@ -658,18 +658,16 @@
 custom%5C%5C
-%5C%5C
 .markup-
@@ -677,9 +677,12 @@
 ));%0A
-%09
+    
 %7D%0A%0A%7D

Revert "http://alexandregiannini.blogspot.de/2011/05/escaping-strings-for-jquery-selectors.html - "If you wish to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, you must escape the character with two backslashes: \\.""