@@ -37,7 +37,26 @@ var hasDuplicate, sortInput,
3737 documentElement . webkitMatchesSelector ||
3838 documentElement . mozMatchesSelector ||
3939 documentElement . oMatchesSelector ||
40- documentElement . msMatchesSelector ;
40+ documentElement . msMatchesSelector ,
41+
42+ // CSS string/identifier serialization
43+ // https://drafts.csswg.org/cssom/#common-serializing-idioms
44+ rcssescape = / ( [ \0 - \x1f \x7f ] | ^ - ? \d ) | ^ - $ | [ ^ \x80 - \uFFFF \w - ] / g,
45+ fcssescape = function ( ch , asCodePoint ) {
46+ if ( asCodePoint ) {
47+
48+ // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
49+ if ( ch === "\0" ) {
50+ return "\uFFFD" ;
51+ }
52+
53+ // Control characters and (dependent upon position) numbers get escaped as code points
54+ return ch . slice ( 0 , - 1 ) + "\\" + ch . charCodeAt ( ch . length - 1 ) . toString ( 16 ) + " " ;
55+ }
56+
57+ // Other potentially-special ASCII characters get backslash-escaped
58+ return "\\" + ch ;
59+ } ;
4160
4261function sortOrder ( a , b ) {
4362
@@ -110,7 +129,14 @@ function uniqueSort( results ) {
110129 return results ;
111130}
112131
132+ function escape ( sel ) {
133+ return ( sel + "" ) . replace ( rcssescape , fcssescape ) ;
134+ }
135+
113136jQuery . extend ( {
137+ uniqueSort : uniqueSort ,
138+ unique : uniqueSort ,
139+ escapeSelector : escape ,
114140 find : function ( selector , context , results , seed ) {
115141 var elem , nodeType ,
116142 i = 0 ;
@@ -140,8 +166,6 @@ jQuery.extend( {
140166
141167 return results ;
142168 } ,
143- uniqueSort : uniqueSort ,
144- unique : uniqueSort ,
145169 text : function ( elem ) {
146170 var node ,
147171 ret = "" ,
0 commit comments