@@ -219,20 +219,34 @@ describe('XRegExp.cache()', function() {
219219
220220describe ( 'XRegExp.escape()' , function ( ) {
221221
222- it ( 'should escape metacharacters' , function ( ) {
222+ it ( 'should escape standard metacharacters' , function ( ) {
223223 expect ( XRegExp . escape ( '[()*+?.\\^$|' ) ) . toBe ( '\\[\\(\\)\\*\\+\\?\\.\\\\\\^\\$\\|' ) ;
224224 } ) ;
225225
226- it ( 'should escape context-aware metacharacters' , function ( ) {
227- expect ( XRegExp . escape ( ']{}-, \n#' ) ) . toBe ( '\\]\\{\\}\\-\\,\\ \\\n\\#' ) ;
226+ it ( 'should escape context-sensitive metacharacters, excluding whitespace' , function ( ) {
227+ expect ( XRegExp . escape ( ']{}-,#' ) ) . toBe ( '\\]\\{\\}\\-\\,\\#' ) ;
228+ } ) ;
229+
230+ it ( 'should escape context-sensitive whitespace' , function ( ) {
231+ // Don't want to explicitly check the escape pattern like this since there are multiple
232+ // valid representations of escaped whitespace
233+ //expect(XRegExp.escape('\t\n\f\r\x20\u2028\u2029')).toBe('\\u0009\\u000a\\u000c\\u000d\\u0020\\u2028\\u2029');
234+
235+ var whitespace = '\t\n\f\r\x20\u2028\u2029' ;
236+ expect ( new RegExp ( '^' + XRegExp . escape ( whitespace ) + '$' ) . test ( whitespace ) ) . toBe ( true ) ;
237+ expect ( XRegExp . escape ( whitespace ) ) . not . toBe ( whitespace ) ;
228238 } ) ;
229239
230240 it ( 'should not escape nonmetacharacters' , function ( ) {
231241 expect ( XRegExp . escape ( 'abc_<123>!\0\uFFFF' ) ) . toBe ( 'abc_<123>!\0\uFFFF' ) ;
232242 } ) ;
233243
234244 it ( 'should escape a nonstring pattern after type converting to a string' , function ( ) {
235- expect ( XRegExp . escape ( { } ) ) . toBe ( '\\[object\\ Object\\]' ) ;
245+ // Don't want to explicitly check the escape pattern like this since there are multiple
246+ // valid representations of escaped whitespace
247+ //expect(XRegExp.escape({})).toBe('\\[object\\ Object\\]');
248+
249+ expect ( new RegExp ( '^' + XRegExp . escape ( { } ) + '$' ) . test ( '[object Object]' ) ) . toBe ( true ) ;
236250 } ) ;
237251
238252 it ( 'should throw an exception when given a null or undefined pattern' , function ( ) {
0 commit comments