Making WordPress.org

Changeset 3151


Ignore:
Timestamp:
05/16/2016 12:57:32 PM (9 years ago)
Author:
ocean90
Message:

Trac: Escape special characters in regular expressions.

See #1541.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/style/trac/wp-trac.js

    r3141 r3151  
    5252    ];
    5353
     54    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_special_characters
     55    function escapeRegExp( string ) {
     56        return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
     57    }
     58
    5459    wpTrac = {
    5560
     
    108113                        }
    109114
    110                         var matchInAttr = new RegExp( '=".*' + match + '.*"' );
     115                        var matchInAttr = new RegExp( '=".*' + escapeRegExp( match ) + '.*"' );
    111116                        if ( matchInAttr.test( $comment ) ) {
    112117                            return match;
Note: See TracChangeset for help on using the changeset viewer.