ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

encode_email doc*ument.write issue in XHTML strict mode (Firefox)

October 15, 2008 10:16am

Subscribe [1]
  • #1 / Oct 15, 2008 10:16am

    Jared Farrish

    575 posts

    The encode email function (which uses doc*ument.write) replaces the DOM instead of inserting the obfuscated email on the page. This is using 1.6.3.

    How do I disable this functionality? I have looked all throughout the control panel and haven’t been able to track it down. I see references to it in the Typography class, but do I have to set this in the class file?

    The following is how I fixed it using the DOM. This is from the encode_email function of the Typography class, ~1800.

    $enc_email_id = 'enc_mail_'.rand(0,100000);
            $enc_email_parent = "<span></span>";
            $bit = array_reverse($bit);
            ob_start();
            
            echo $enc_email_parent;
    ?><scr*ipt type="text/javascript">
    //<![CDATA[
    var l=new Array();
    <?php
        
        $i = 0;
        foreach ($bit as $val)
        {
    ?>l[<?php echo $i++; ?>]='<?php echo $val; ?>';<?php
        }
    ?>
    
    var enc_email_output = '';
    for (var i = l.length-1; i >= 0; i=i-1){ 
        if (l[i].substring(0, 1) == ' ') {
            enc_email_output += "&#"+unescape(l[i].substring(1))+";"; 
        } else {
            enc_email_output += unescape(l[i]);
        }
    }
    document.getElementById('<?php echo $enc_email_id; ?>').inner*HTML = enc_email_output;
    //]]>
    </scr*ipt><?php
  • #2 / Oct 15, 2008 11:13am

    Robin Sowell

    13255 posts

    Do you just want emails to not be encoded in entries?  If so- it’s on a per weblog basis- the setting in ‘Admin- Weblog Admin- Weblog Management’ under posting prefs.  Turn off auto-linking emails and urls.

    That in the ballpark?

  • #3 / Oct 15, 2008 11:19am

    Jared Farrish

    575 posts

    To be perfectly honest, I don’t mind if they’re encoded; the encoder just doesn’t work as written. That particular setting didn’t look to me to do it; it would seem obfuscation would be different from auto-linking non-tagged links and emails?

    I don’t like changing the core codebase, either. I’ll probably just turn it off until it’s fixed. Having a global override in config.php would probably also be nice for the specific encode_mail auto-function.

    And technically, innerHTML isn’t any better than doc*ument.write. Should be an append for a fully DOM-flavored fix.

    Thanks!
    Jared

  • #4 / Oct 15, 2008 12:50pm

    Robin Sowell

    13255 posts

    Ah- you’re right- auto_link gets them in a format that triggers the ‘encode’ check- which is in the template class- (and encoding can be turned off there via var $encode_email)- which calls the function class (encode_email($str))- which basically… pulls in the Typography::encode_email($email, $title, TRUE);.

    All of which is a really long way for me to say- I’m not dead sure how it’s failing.  It works- but method it uses to replace it is problematic?  Just want to be sure I get what the ultimate problem is.  And if it’s something that needs a bug fix.  The DOM is not my strong point.

  • #5 / Oct 15, 2008 2:08pm

    Jared Farrish

    575 posts

    Ok, I put together a test page and found out what I think is actually causing the problem I’m seeing.

    Using Firefox 3.0.

    In this case, using the jQuery library (1.2.6) and the wrapInner method of that library, it causes the page to go into a never-ending loop. When I hit stop and Inspect Element in Firebug, I get a blank, plain-jane DOM with only the inserted blah blah.

    What I think is happening is that, when doc*ument.write happens, it attempts to put the text on the page, but does so in a way in which the wrapInner method then sees another DOM (created by doc*ument.write). From my searches on the error, the suggestion is the doc*ument.write does not work with XHTML doctypes.

    That’s my guess, fwiw.

    Here is the test code to reproduce (I saved it to my desktop and ran it from there). You’ll also want to do a find/replace on ‘*’ and save before running.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>XHTML Strict Mode - doc*ument.write test</title>
    <scr*ipt type="text/java*script" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.js"></scr*ipt>
    <scr*ipt type="text/java*script">
    $(document).ready(function(){
        $('div.block_page_body_parent').wrapInner('<div class="block"></div>');
    });
    </scr*ipt>
    </head>
    <body>
    <div class="block_page_body_parent">
    <h1>XHTML Strict Mode</h1>
    <h3>doc*ument.write test</h3>
    <p>This content should not be replaced.<br />
    <scr*ipt type="text/java*script"><br />
    //<![CDATA[<br />
    var l=new Array();<br />
    l[0]='>';l[1]='a';l[2]='/';l[3]='<';l[4]=' 117';l[5]=' 100';l[6]=' 101';l[7]=' 46';l[8]=' 116';l[9]=' 110';l[10]=' 117';l[11]=' 64';l[12]=' 97';l[13]=' 105';l[14]=' 112';l[15]=' 97';l[16]=' 116';l[17]=' 46';l[18]=' 115';l[19]=' 105';l[20]=' 117';l[21]=' 76';l[22]='>';l[23]='\"';l[24]=' 117';l[25]=' 100';l[26]=' 101';l[27]=' 46';l[28]=' 116';l[29]=' 110';l[30]=' 117';l[31]=' 64';l[32]=' 97';l[33]=' 105';l[34]=' 112';l[35]=' 97';l[36]=' 116';l[37]=' 46';l[38]=' 115';l[39]=' 105';l[40]=' 117';l[41]=' 76';l[42]=':';l[43]='o';l[44]='t';l[45]='l';l[46]='i';l[47]='a';l[48]='m';l[49]='\"';l[50]='=';l[51]='f';l[52]='e';l[53]='r';l[54]='h';l[55]='a ';l[56]='<';<br />
    for (var i = l.length-1; i >= 0; i=i-1){ <br />
    if (l[i].substring(0, 1) == ' ') doc*ument.write("&#"+unescape(l[i].substring(1))+";"); <br />
    else doc*ument.write(unescape(l[i]));<br />
    }<br />
    //]]><br />
    </scr*ipt><br />
    </div><br />
    </body><br />
    </html>

  • #6 / Oct 16, 2008 1:34pm

    Robin Sowell

    13255 posts

    Jared- just wanted to say thanks and let you know I’m poking it.  And yep- I finally ‘get’ what’s up.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases