WordPress loading javascript with strange character set - javascript

I'm using WordPress 5.1 with Yoast SEO. Yoast SEO relies on the file components.js which is throwing the following error in the console (I've edited this for brevity - it's a very long string)
Uncaught SyntaxError: Invalid regular expression:
/[A-Za-zªµºÀ-ÖØ-öø-ƺƻƼ-Æ¿Ç€-ǃDŽ-ʓʔʕ-ʯʰ-ʸʻ-ËË-Ë‘Ë -ˤˮͰ-ͳͶ-ͷͺͻ-ͽͿΆΈ-ΊΌΎ-Î
The identical string does not appear in the file, though the file does include the following line when looking with a text editor:
["+"A-Za-zªµºÀ-ÖØ-öø-ƺƻƼ-Æ¿Ç€-ǃDŽ-ʓʔʕ-ʯʰ-ʸʻ-ËË-Ë‘Ë -ˤˮͰ-ͳͶ-ͷͺÍ
The line looks like this when looking through the webhost control panel:
["+"A-Za-zªµºÀ-ÖØ-öø-ƺƻƼ-ƿǀ-ǃDŽ-ʓʔʕ-ʯʰ-ʸʻ-ˁː-ˑˠ-ˤˮͰ-ͳͶ-ͷͺͻ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁ҂Ҋ-ԯԱ-Ֆՙ՚-՟ա-և։ःऄ-हऻ
The only odd thing is that the database had a mix of character sets (latin1, utf8 and utf8mb4) which I have attempted to fix and all tables now use utf8mb4_uncode_ci (this was chosen as it was the most common character set in the db).
There is also a mix of InnoDB and MyISAM table types. The site has a number of  characters around the site which is a common indicator of character set issues as far as I can tell.
So I'm guessing for some reason WordPress is loading the javascript file with the incorrect character set which is creating errors.
Is there a way to fix this? I'm a bit baffled.

Fixed.
This was due to blog_charset being set to UTF-7 in wp_options. Changing this to UTF-8 has solved the problem

Related

js files are loading in unreadable format

I was working on a Web App. I used a "✗" UTF-8 character as a delete button. Eclipse asked me to save file in UTF-8 format i told yes. Everything worked fine. But next day when i ran the app again it is throwing exception "Uncaught SyntaxError: Unexpected token ILLEGAL". When i checked it, all javascript file is loading in unreadable format. See image below.
I tried to replace that character with its UNICODE "✗" and saved all js files in default encoding, but didn't help.
Do anyone know why is this happening?
It sounds like you saved in a different text format than you loaded it and/or loaded it in a different text format that you saved it. Without recommending a tool, I would see if you can use something to change the code-page/text-format and then try stuff.
However, seeing as what you are showing on teh screen is 3rd part stuff, you could just more easily re-download it where you got it the first time, or perhaps unpack it if you saved the installer/zip-file.

Uncaught SyntaxError: Unexpected token ILLEGAL - when splitting up a file

I have one big file that consists of HMTL, Javascript and CSS and I wish to split it up to make it more managable. But when I split the HTML file up and save it as seperate HTML, Javascript and CSS files I get the error :
Uncaught SyntaxError: Unexpected token ILLEGAL
When I click on the error it takes me to the file in the browser and my file consists of only Chinese symbols.
I have tried finding the answer and apparently I have hidden characters in my code but how am I meant to find these ?
What can I do to fix this issue ?
Mojibake like this can occur when the program reading in a file is unable to figure out what kind of encoding a file is using and guesses the encoding incorrectly. It could be that you have a weird character lurking in your file somewhere that is completely throwing off the encoding detection.
Some encoding schemes provide a way to mitigate this problem by using a BOM, which is a short marker at the beginning of the file that indicates the type of encoding that the file uses. BOMs have advantages and disadvantages, but one big advantage is that they firmly establish a file's encoding so that the program loading the file doesn't have to guess what the encoding is. It sounds like including the BOM in your file remedied your issue.
For more information on encoding, see:
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

SyntaxError Invalid character '\u8220'

There is a GTK+ Javascript ( Seed ) Database Tutorial here:
Javascript GTK+ Seed SqLite Tutorial
When I cut and paste the code into Geany or Gedit and compile it throws this error:
** (seed:19814): CRITICAL **: Line 3 in ./db.js: SyntaxError Invalid character '\u8220'
After unsuccessfully trying to locate and delete the offending character not once but countless times I gave up. Then I simply typed all the code into Geany and then it compiles and executes no errors .
My question is do we have a way for Geany or Gedit to actually display or even place mark such invisible characters as typing in small programs I have no issues with but as they become larger then it becomes exceedingly weary and inefficient, especially when one is trying to learn a new framework.
My apologies if this is not a proper question for Stackoverflow but I truly am trying to understand how the cutting and pasting process adds in these characters, I have looked through the html and I see no such character in the tutorial.
The whole point of having sample code is to allow the end-user to cut and paste and compile and learn ? But this gave me a real bad headache till I finally decided to type it all in and then everything works.
Your editors are displaying the offending character, you're just not recognizing it. The code point in the error message refers to the left double quotation mark character, which is indeed present in some examples on the linked page. This is almost certainly an unintentional effect of some well-meaning text editing software. As you correctly point out, code examples are intended to be copied and pasted, and you should report a bug to the site admins.
To add to the confusion, the error message printed by Seed's JavaScript parser is wrong: it misrepresents the \u201c character (which has decimal code 8220) as \u8220. This is why attempts to search for \u8220 fail.
To fix the problem in your file, you need to replace the character with an upright quotation mark. To search for an arbitrary Unicode character in a GTK-based text editor, press ctrl-f to initiate search and input the character by with ctrl-shift-u followed by the code point, in this case 201c. You will need to do the same for the right quotation mark, whose hex code is 201d.

JS backslash escape char being converted to non-escaping character by Shift JIS

I'm currently working on a website that has two versions, one American website that's served as utf-8 and one Japanese version that's served as Shift JIS. The site is generated using Perl.
The problem:
I'm serving Javascript akin to the following.
var text = "test \"quote\"";
Which, on the Japanese site, is returning an error "Uncaught SyntaxError: Unexpected identifier." This is because the backslash is being converted to an elongated backslash character \, which isn't seen as an escape character and thus is breaking the line.
I can't seem to find anyone else running into this problem which makes me suspicious that there isn't something fundamentally wrong with our website. Has anyone encountered a similar situation and found a solution?
Many thanks
I found some helpful information here:
Why browser is showing different back slash for a email validation regex. How to prevent that?
Which lead me to this upsetting hack:
var text = "test ¥"quote¥"";
This works perfectly. Now, obviously this isn't the way to do it, but it will enable other devs to get on testing other JS interactions on the site while I concentrate on refactoring this code into something that doesn't rely on character escaping. I hope this information helps someone else at some point!

How to setup Eclipse to be warned about trailing comma in JavaScript

As many of us know, IE7 is not quite friendly with JavaScript code containing trailing commas, which can be a large problem for projects using modern JS framerworks and containing a lot of JS code.
In a pretty good article on the subject, the author mentions:
On the tools front, my preference for combating these devils is the Eclipse JavaScript Development Tools. The JavaScript source editor in JSDT flags trailing commas as errors: http://www.enterprisedojo.com/wp-content/uploads/2010/12/jsdtRules.png
However, using Eclipse Indigo with WTP/JSDT, I'm not seeing trailing commas as errors, and I can't find a proper setting to fix this.
How do I setup Eclipse to flag trailing commas in JavaScript as errors?
It looks like the fix for another bug involving erroneous syntax errors on the comma operator also removed the syntax error on trailing commas in initializers. That's technically correct; the standard says they're allowed and IE7 is just nonconformant. There's a feature request open asking that they be reinstated.
Slightly off topic, but you should also look into using JSLint to check the syntax of the JavaScript code. It will warn you about the trailing comma, but also about many other potential problems. There is a good plugin for Eclipse, http://marketplace.eclipse.org/content/phonegap-android-jslintjshint. The instructions for setting it up: http://www.mobiledevelopersolutions.com/home/announce-1/mds12released-nowwithjslintjshint
Make sure you're in the correct perspective (ie JavaScript as opposed to Java).
Also, I found in Helios that if I added a JS file to the project by right-clicking and adding a new 'File' (which I would then name with a .js extension) didn't make the UI pick up that it should be treated as a JS file--no syntax highlighting, checking, etc. If I added it specifically using the new JavaScript file option, it worked fine.

Categories

Resources