New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError on page change - bounty of €100 #132

Closed
nealfletcher opened this Issue Jul 24, 2017 · 11 comments

Comments

Projects
None yet
2 participants
@nealfletcher

nealfletcher commented Jul 24, 2017

After clicking on a page link I keep repeatedly getting the following error:
SyntaxError: Unexpected identifier 'img'. Expected a ';' after the for loop condition expression.

This is preventing a change in the URL, it's highlighting this error in the title tag of the site, anyway not sure what's causing it, can provide a link if needs be? If anyone could shed any light that'd be great!

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Jul 24, 2017

Owner

EDIT: Solved in the course of this discussion at jQuery forum - The bounty of €100 went to "jakecigar"


Is this happening within an inline script? If yes, my guess is:

Because it's occuring in a for loop, that you have a "less than sign" ("<") followed directly by an alpha-character. Please try adding a space between the "<" character and the letter. This is a known error in jQuery core, which I currently don't know how to fix.
(I have worked around the same bug on 4nf.org, as described above)

For example, it might be worth trying to:

  • Catch the error

and then

  • Dynamically add a CDATA section to the whole inline script text
Owner

arvgta commented Jul 24, 2017

EDIT: Solved in the course of this discussion at jQuery forum - The bounty of €100 went to "jakecigar"


Is this happening within an inline script? If yes, my guess is:

Because it's occuring in a for loop, that you have a "less than sign" ("<") followed directly by an alpha-character. Please try adding a space between the "<" character and the letter. This is a known error in jQuery core, which I currently don't know how to fix.
(I have worked around the same bug on 4nf.org, as described above)

For example, it might be worth trying to:

  • Catch the error

and then

  • Dynamically add a CDATA section to the whole inline script text

@arvgta arvgta added the bug label Jul 24, 2017

@nealfletcher

This comment has been minimized.

Show comment
Hide comment
@nealfletcher

nealfletcher Jul 24, 2017

Ah I see, thanks for getting back to me on this one...You can see the bug in question here: http://elliottdev.nealfletcher.co.uk

If you click on 'Studio' in the top right, you'll see the error in the console. Where would you suggest adding the space exactly?

nealfletcher commented Jul 24, 2017

Ah I see, thanks for getting back to me on this one...You can see the bug in question here: http://elliottdev.nealfletcher.co.uk

If you click on 'Studio' in the top right, you'll see the error in the console. Where would you suggest adding the space exactly?

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Jul 24, 2017

Owner

Thanks for your swift reply and the link! Because I'm currently not at my own PC, I can't see the exact text of the error message. Please try adding the space directly after the "less than sign"...

Here - I think I've pinpointed it:

h<i.length;h++

Just add a space after the "less than sign"

Owner

arvgta commented Jul 24, 2017

Thanks for your swift reply and the link! Because I'm currently not at my own PC, I can't see the exact text of the error message. Please try adding the space directly after the "less than sign"...

Here - I think I've pinpointed it:

h<i.length;h++

Just add a space after the "less than sign"

@nealfletcher

This comment has been minimized.

Show comment
Hide comment
@nealfletcher

nealfletcher Jul 24, 2017

I think I've got to the bottom of it – there was some inline script being added by Wordpress that contained a < sign, disabling this has fixed that issue :)

One small problem now though is that the URL doesn't seem to be updating on page change for some reason?

nealfletcher commented Jul 24, 2017

I think I've got to the bottom of it – there was some inline script being added by Wordpress that contained a < sign, disabling this has fixed that issue :)

One small problem now though is that the URL doesn't seem to be updating on page change for some reason?

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Jul 24, 2017

Owner

Glad we found the exact position of the error.

I just checked the console - very weird - no other errors...

Just another guess -> maybe Wordpress needs the inline script you disabled.
Maybe the ideal solution is to really insert a space in the inline script instead.
(You may be able to edit the PHP of the respective plugin in the WP-Admin)

Owner

arvgta commented Jul 24, 2017

Glad we found the exact position of the error.

I just checked the console - very weird - no other errors...

Just another guess -> maybe Wordpress needs the inline script you disabled.
Maybe the ideal solution is to really insert a space in the inline script instead.
(You may be able to edit the PHP of the respective plugin in the WP-Admin)

@nealfletcher

This comment has been minimized.

Show comment
Hide comment
@nealfletcher

nealfletcher Jul 24, 2017

Hmm I don't think so as the URL wasn't changing before this script was disabled. The script in question is the emojicon script that's added by default by WP to enable emojicons. Any other ideas?

nealfletcher commented Jul 24, 2017

Hmm I don't think so as the URL wasn't changing before this script was disabled. The script in question is the emojicon script that's added by default by WP to enable emojicons. Any other ideas?

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Jul 24, 2017

Owner

Am thinking, but no other ideas at the moment... Might have a look at your HTML when I have the time...

Owner

arvgta commented Jul 24, 2017

Am thinking, but no other ideas at the moment... Might have a look at your HTML when I have the time...

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Jul 24, 2017

Owner

One thing that came to my attention is that the canonical URL always seems to be:

<link rel="canonical" href="http://elliottdev.nealfletcher.co.uk">

...for both "Work" and "Studio"?

Ajaxify uses the canonical URL, when it is given...

EDIT: Forget about this last comment - it was because the page wasn't re-loading

Owner

arvgta commented Jul 24, 2017

One thing that came to my attention is that the canonical URL always seems to be:

<link rel="canonical" href="http://elliottdev.nealfletcher.co.uk">

...for both "Work" and "Studio"?

Ajaxify uses the canonical URL, when it is given...

EDIT: Forget about this last comment - it was because the page wasn't re-loading

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Jul 27, 2017

Owner

Regarding a solution to the original problem - the "less than sign" that causes the inline script to crash - it would require, in a first step, to catch the error when appending the failing inline script.

I have tried various

try...catch

statements in different places, but they don't seem to prevent a "hard error" - in effect, they do nothing at all.

I believe, that would be the first step to combat the bug...

Here is the salient code explicitly:

 addtext: function (t, type) { //Add one inline JS script - main function
        if(!t || !t.length) return; //Ensure input
        if(!type) type = 'text/javascript'; //Validate type
        if(inlineappend || !type.iO('text/javascript')) try { return _apptext(t, type); } catch (e) { $.log("Error in apptext: " + t + "\nType: " + type + "\nCode: " + console.debug(e)); }
        
        try { $.globalEval(t); } catch (e1) { //instead of appending, try an eval
            try { eval(t); } catch (e2) {
                $.log("Error in inline script : " + t + "\nError code : " + e2);
            }
        }
    },
    apptext: function (t, type) { //Append a single inline script to the main content div
        var scriptNode = document.createElement('script'); //low-level assembly of script node
        scriptNode.type = type;
        scriptNode.appendChild(document.createTextNode(t));
        try { cd0.appendChild(scriptNode); } catch (e)  { $.log("Bad inline script text in apptext: " + t); }
    },

Any ideas?

Owner

arvgta commented Jul 27, 2017

Regarding a solution to the original problem - the "less than sign" that causes the inline script to crash - it would require, in a first step, to catch the error when appending the failing inline script.

I have tried various

try...catch

statements in different places, but they don't seem to prevent a "hard error" - in effect, they do nothing at all.

I believe, that would be the first step to combat the bug...

Here is the salient code explicitly:

 addtext: function (t, type) { //Add one inline JS script - main function
        if(!t || !t.length) return; //Ensure input
        if(!type) type = 'text/javascript'; //Validate type
        if(inlineappend || !type.iO('text/javascript')) try { return _apptext(t, type); } catch (e) { $.log("Error in apptext: " + t + "\nType: " + type + "\nCode: " + console.debug(e)); }
        
        try { $.globalEval(t); } catch (e1) { //instead of appending, try an eval
            try { eval(t); } catch (e2) {
                $.log("Error in inline script : " + t + "\nError code : " + e2);
            }
        }
    },
    apptext: function (t, type) { //Append a single inline script to the main content div
        var scriptNode = document.createElement('script'); //low-level assembly of script node
        scriptNode.type = type;
        scriptNode.appendChild(document.createTextNode(t));
        try { cd0.appendChild(scriptNode); } catch (e)  { $.log("Bad inline script text in apptext: " + t); }
    },

Any ideas?

@arvgta arvgta changed the title from SyntaxError on page change to SyntaxError on page change - bounty of €100 Aug 9, 2017

arvgta added a commit that referenced this issue Aug 13, 2017

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Aug 13, 2017

Owner

Fixed presumably! Therefore closing...

Owner

arvgta commented Aug 13, 2017

Fixed presumably! Therefore closing...

@arvgta arvgta closed this Aug 13, 2017

@arvgta arvgta changed the title from SyntaxError on page change - bounty of €100 to SyntaxError on page change Sep 2, 2017

@arvgta arvgta reopened this Sep 3, 2017

@arvgta arvgta changed the title from SyntaxError on page change to SyntaxError on page change - bounty of €100 Sep 3, 2017

arvgta added a commit that referenced this issue Sep 3, 2017

Fix for issue #132
See issue #132

Now seems to work on non-Chrome browsers, too...

arvgta added a commit that referenced this issue Sep 3, 2017

arvgta added a commit that referenced this issue Sep 3, 2017

arvgta added a commit that referenced this issue Sep 3, 2017

arvgta added a commit that referenced this issue Sep 3, 2017

Merge pull request #135 from arvgta/arvgta-patch-1
Fix for issue #132 - with global replace

@arvgta arvgta changed the title from SyntaxError on page change - bounty of €100 to SyntaxError on page change Sep 10, 2017

@arvgta arvgta added the wontfix label Sep 10, 2017

@arvgta arvgta closed this Sep 10, 2017

@arvgta

This comment has been minimized.

Show comment
Hide comment
@arvgta

arvgta Sep 10, 2017

Owner

Summary: When encountering this bug, please edit the PHP of the plugin causing the error and insert a space after the "less than" sign or disable the respective plugin altogether.

Owner

arvgta commented Sep 10, 2017

Summary: When encountering this bug, please edit the PHP of the plugin causing the error and insert a space after the "less than" sign or disable the respective plugin altogether.

@arvgta arvgta removed the wontfix label Sep 28, 2017

@arvgta arvgta reopened this Sep 28, 2017

@arvgta arvgta closed this Sep 29, 2017

@arvgta arvgta changed the title from SyntaxError on page change to SyntaxError on page change - bounty of €100 Oct 29, 2017

@arvgta arvgta reopened this Oct 29, 2017

arvgta added a commit that referenced this issue Nov 6, 2017

Proposed fix for #132
[Demo](https://4nf.org/)

Feel free to comment

@arvgta arvgta changed the title from SyntaxError on page change - bounty of €100 to SyntaxError on page change Nov 6, 2017

arvgta added a commit that referenced this issue Nov 6, 2017

arvgta added a commit that referenced this issue Nov 6, 2017

@arvgta arvgta closed this Nov 6, 2017

@arvgta arvgta changed the title from SyntaxError on page change to SyntaxError on page change - bounty of €100 Nov 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment