http://www.perlmonks.org?node_id=758385

Free Nodelet gets templating features says one of the main features of the new enhancements are that it will "No longer foul up square brackets in JavaScript inside HTML comments", but when I tried putting [Free Nodelet Hack] Highlight monk names accordingly their XP level in my Free Nodelet, the square brackets within the JavaScript were mangled^H^H^H^H^H^H^H^H processed as if they were PM links.

I was further surprised to find that if I comment just one of them (e.g. change "var Pope = [979];" to "var Pope = `[979];") then none of them are mangled. It doesn't matter which one I quote - quoting any one of them stops all of them being processed as links.

Without the quote, "var Pope = [979];" is rendered as "var Pope = <a href="?node=979">979</a>;", which doesn't work very well at all.

All I did was cut and paste the code from [Free Nodelet Hack] Highlight monk names accordingly their XP level, and it certainly appears to have the JavaScript enclosed in HTML comments ("<!-- ... -->").

Is this expected behaviour? Might I have done something wrong?

update: There was a bug but tye has fixed it!!

update2: Removed the quote from the example after "Without the quote".

Replies are listed 'Best First'.
Re: Free Nodelet, JavaScript and PM links (words)
by tye (Sage) on Apr 18, 2009 at 01:57 UTC

    You have to read the sentence that you quoted all the way to the end:

    No longer foul up square brackets in JavaScript inside HTML comments

    For example, in my Free Nodelet:

    <script type="text/javascript"><!-- alert("a[n] alert"); --></script>

    has no problem with the square brackets.

    - tye        

      But it is, I think. Omitting most of the script, it is like this:

      <script type="text/javascript"> <!-- // "When a society has no colored pants to differentiate class... ... setTimeout('Colorize()', 600); // --> </script>

      I even tried getting rid of the "//" in front of the "-->", but still it wasn't right.

      update: I tried putting your example in my free nodelet and it is rendered as:

      <script type="text/javascript"><!-- alert("a<a href="?node=n">n</a> alert"); --></script>

      Maybe there is an option I must set somewhere??

        The code I included that parsed the Free Nodelet contents doesn't look at any user settings...

        Aha! Here is the problem code:

        if( $html =~ /`/ ) { $html= htmlcode( 'expandfreenodelet','', $html ); } else { $html =~ s/\[(.*?)\]/handleLinks($1,getId($NODE))/egs; }

        So the special handling of HTML comments doesn't happen unless there is at least one ` somewhere in your Free Nodelet. I'll fix that.

        Thanks for the bug report and the patience at my missing some of the details you provided.

        Update: I've fixed it.

        - tye        

        Omitting most of the script

        That requires that I omit most of my diagnosis. :)

        No, // won't matter. Also, contrary to the HTML specification, not even -- matters (as far as PerlMonks is concerned "HTML comments" simply start with <!-- and end with -->).

        Since you don't give me much to work with, I'll give you the code (that manipulates the contents of the Free Nodelet) and you can diagnose the problem:

        $html =~ s{`([\[\]]|`+|(\w+)([%&\\]?)`?|.)}{ my $s= $1; if( '[' eq $s ) { $just ? '[' : '`{'; } elsif( ']' eq $s ) { $just ? ']' : '`}'; } elsif( defined $2 ) { my( $key, $suff )= ( $2, $3 ); my $val; if( $key =~ /^_./ ) { $val= $q->param($key); $val= $q->param( substr($key,1) ) if ! defined $val; } else { $key =~ s/_name$/_title/i; $val= $var{ lc $key }; } if( ! defined $val ) { $val= "`$key$suff`" } elsif( $suff eq '%' ) { $val= $q->escape($val); } elsif( $suff eq '&' ) { $val= $q->escapeHTML($val); } elsif( $suff eq '\\' ) { $val=~ s/(['"\\])/\\$1/g; } $val; } elsif( $s =~ /^`/ ) { $just ? $s : '`'.$s; } else { $just ? '`'.$s : '``'.$s; } }seg; return $html if $just; $html =~ s{(<!--.*?-->)|\[([^\[\]]{1,4096})\]}{ $1 ? $1 : handleLinks($2) }seg; $html =~ s{`([{}]|`+|.)}{ my $s= $1; if( '{' eq $s ) { '['; } elsif( '}' eq $s ) { ']'; } elsif( $s =~ /^`/ ) { $s; } else { '`'.$s; } }seg;

        - tye