arvgta / ajaxify

Ajaxify - An Ajax Plugin
https://4nf.org/
274 stars 124 forks source link

Uncaught SyntaxError: Unexpected identifier - bounty of €100 #125

Closed arvgta closed 7 years ago

arvgta commented 7 years ago

I would like to issue a bounty of €100, payable via PayPal, for anybody, who can offer a generic solution to this bug within the Ajaxify code or has any ideas that lead to the resolution of the bug!


EDIT: This bug seems to be a known error in jQuery core (!)

Therefore, I will wait until jQuery solves it by itself. Also, from an Ajaxify point of view this issue can be regarded as GIGO(garbage in - garbage out). If you encounter this bug, please bypass it by cleaning the HTML input!


I've pinpointed the line that falls over to be in the following block of code:

_apptext = function (t, type) { //Append a single inline script to the main content div
   scriptNode = document.createElement('script'); //low-level assembly of script node
   scriptNode.type = type;
   scriptNode.appendChild(document.createTextNode(t));
   cd0.appendChild(scriptNode); //this line falls over
   return true;
},

i.e. the following line falls over:

cd0.appendChild(scriptNode);

This error has been "introduced" since the inclusion of the Custom Share Buttons with Floating Sidebar Wordpress plugin on 4nf.org. Error does not show in the console when Ajaxify is shut off. You can reproduce the error in any browser, when navigating to any sub-page and looking at the console:

Demo at 4nf.org

Presumably, the solution is to escape entities like "<" as soon as possible. When I escape the "<" with "< " (i.e. add a space) most inline scripts work, but not ones, where the "<" is intended to be an opening tag...


Salient code

function csbwfsGetCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) != -1) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

...becomes something like this:

function csbwfsGetCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i
...
SyntaxHighlighter.autoloader(...);

However, this code triggers the same bug:

<script>for(i=0, ca=10; i<ca; i++);</script>

I presume that it is caused by a "<" , that's to say a"less than sign" within inline scripts, that is interpreted as an HTML opening tag (as can be seen rather explicitly in Chrome). Verified that _onetxt() is being passed the corrupted inline script text already. So the inline script text is being corrupted rather early...