Changeset 1129 for trunk


Ignore:
Timestamp:
11/22/08 00:07:55 (11 years ago)
Author:
nicholasbs
Message:

Fixes #1337 (GetHtml? screws up links with dollars signs in them)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/GetHtml/TransformInnerHTML.js

    r1034 r1129  
    6565        } 
    6666} 
     67 
    6768/**  
    6869  * Cleans HTML into wellformed xhtml 
     
    8687                replace(c[10], ' ');//trim extra whitespace 
    8788        if(Xinha.is_ie && c[13].test(sHtml)) { 
    88                 sHtml = sHtml.replace(c[13],'$1'+this.stripBaseURL(RegExp.$3)+'"'); 
    89         } 
     89          sHtml = sHtml.replace(c[13],'$1'+Xinha._escapeDollars(stripBaseURL(RegExp.$3))+'"'); 
     90        } 
     91 
    9092        if(this.config.only7BitPrintablesInURLs) { 
    9193                if (Xinha.is_ie) c[13].test(sHtml); // oddly the test below only triggers when we call this once before (IE6), in Moz it fails if tested twice 
    9294                if ( c[13].test(sHtml)) { 
    9395                        try { //Mozilla returns an incorrectly encoded value with innerHTML 
    94                                 sHtml = sHtml.replace(c[13], '$1'+decodeURIComponent(RegExp.$3).replace(/([^!-~]+)/g,function(chr){return escape(chr);})+'"'); 
     96                          sHtml = sHtml.replace(c[13], '$1'+Xinha._escapeDollars(decodeURIComponent(RegExp.$3).replace(/([^!-~]+)/g, function(chr)  
     97                                                                                                                       {return escape(chr);}))+'"'); 
    9598                        } catch (e) { // once the URL is escape()ed, you can't decodeURIComponent() it anymore 
    96                                 sHtml = sHtml.replace(c[13], '$1'+RegExp.$3.replace(/([^!-~]+)/g,function(chr){return escape(chr);})+'"'); 
     99                          sHtml = sHtml.replace(c[13], Xinha._escapeDollars('$1'+RegExp.$3.replace(/([^!-~]+)/g,function(chr){return escape(chr);})+'"')); 
    97100                        } 
    98101                } 
     
    216219        return html; 
    217220}; 
     221 
     222/**  
     223  * Escapes dollar signs ($) to make them safe to use in regex replacement functions by replacing each $ in the input with $$. 
     224  *  
     225  * This is advisable any time the replacement string for a call to replace() is a variable and could contain dollar signs that should not be interpreted as references to captured groups (e.g., when you want the text "$10" and not the first captured group followed by a 0). 
     226  * See http://trac.xinha.org/ticket/1337 
     227  */ 
     228Xinha._escapeDollars = function(str) { 
     229  return str.replace(/\$/g, "$$$$"); 
     230}; 
Note: See TracChangeset for help on using the changeset viewer.