Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1052

Browser's behavior UTF-8 page with extra character like U+FFFE (ERROR by ajax) XML Parsing Error: not well-formed

$
0
0

We are developing some JSF web applications with PrimeFaces.

It is possible in inputText to copy/paste text with a non UTF-8 character like `` (Here is the character) and save the page. But there is an error in the rendered HTML:

Error: Forbidden code point U+fffe.

The browser doesn't show (hide) the error, it shows the non UTF-8 character (works like in a normal case)!

But, after this page will be sent from the server to the browser in an Ajax response, the browser shows an error in the console! And the user can see the error!

Console message:

XML Parsing Error: not well-formed

What is the best way to handle this error?

I have a lot of bad ideas. :)

  1. Validate input before save!

    • Client side with Javascript can be general, but not secure.
    • Replace bad characters to '' can cause misunderstanding by user. There are a lot of bad characters which are like right-accented characters.
    • I can make a validator for JSF, but I should register it to all inputText components one by one.
  2. Perhaps I can search the Javascript what parses Ajax responses and patch it.

'Minimal' reproduction:

Github link

  1. Download the source
  2. mvn clean package
  3. download wildfly 32.0.1.Final
  4. copy the war from project's target to wildfly/standalone/deployments
  5. start wildfly
  6. http://localhost:8080/utf8/main.xhtml
  7. After copy paste the bad character and click the button, its failed.

I think, the main problem is that Ajax uses XML. And there are a lot of characters in UTF-8 that aren't valid in XML.

How can I check my string fast in Java if there are any invalid characters?

Some other happenings

There are some strange behavior. U+0002 character is removed by jsf writer.

  1. I type U+0002 and click the button
  2. Server side bean property was set.
  3. But the renderResponse phase the Html writer logic has removed this character.

With U+FFFE character is other. I wrote a validator and it throws ValidatorException, but by the renderResponse Phase U+FFFE character appeared.

I think this mojarra bug can be very identical bug:

https://github.com/eclipse-ee4j/mojarra/issues/4516


Viewing all articles
Browse latest Browse all 1052

Trending Articles