[BUG-1902]Web Dev encoding error

Hi,

I want to use Chinese in web pages,but they are not displayed correctly.
I tried use “u”,before string,and they showed another error.image image
The HTTP Method is doGet.
Ignition 8.1.2.
I tried linux,windows,they have the same result.
How to fix it?
Does it support UTF-8?

I have encountered this problem in all scripts. it looks like a bug in jython.

Not a bug. The u'xyz'’ syntax is necessary if the string constant contains any unicode. The latter display in the browser is a browser problem I think, or a failure to deliver a content-type that specifies UTF8.

Return a contentType key in your dictionary as well; try text/html;charset=UTF-8. By default the html return key will set the content-type to text/html, with no explicit charset - and if you aren’t returning a full HTML declaration (see strict mode vs quirks mode) and a meta-charset header, the browser has no way to assume the encoding and has to ‘guess’ - which generally means it will use the OS default charset.

In firefox,script without ‘u’,I set the browser charset to Unicode,and it runs well.
That is weird…
Here is the file.
Added meta charset=“utf-8”.
index.html (2.6 KB)
But,
This file runs well in Web Dev(Default encode).
I copy text to script, it runs error,unless set browser charset manually.
It can’t work with ‘u’,Chinese word will be replaced by ?.
Part of script:
image

There’s a bug in Wevdev I just noticed. We’re parsing the provided HTML string with ISO-8859-1, regardless of content type specified. We’ll need to fix the HTML encoding on our end - in the meantime you could probably work around it by manually writing your content to the servlet response object…

Thanks.

Excuse me.Is there a schedule?
When will this bug be fixed?And does it will be fixed in 8.1.x?
More infomation:
In Web Dev ,function(system.util.jsonEncode) will break the encoding.
I noticed that today.

No, no schedule. It's on our list to be fixed, and could be picked up at any time.

Yes, it will be fixed in a future 8.1.x update.

This would be a different issue, unrelated to what's happening in Webdev, but I don't think it's the jsonEncode function that's the problem.

In the meantime, you can workaround the issue by adding this line before you return your HTML body:
request["servletResponse"].setCharacterEncoding("UTF-8")

As in this example:

	html = u'''<!DOCTYPE html>
	<html><head><meta charset="UTF-8"></head>
	<body>
	組知画性底増江切的賞匿得価令。導者春道教将棚講厚個渡育触抗止
	</body>
	</html>'''
	request["servletResponse"].setCharacterEncoding("UTF-8")
	return {'html': html, 'contentType': 'text/html;charset=utf-8'}

Which works correctly on Windows:
image

2 Likes