Skip to content
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

UTF-8 Asset is not output as UTF-8 #65

Closed
crystalcyril opened this issue Feb 20, 2014 · 9 comments
Closed

UTF-8 Asset is not output as UTF-8 #65

crystalcyril opened this issue Feb 20, 2014 · 9 comments

Comments

@crystalcyril
Copy link

This is me again, which reported issue #62 and #63.

It seems that the version 1.5.7 does not properly fixed the issue. I am running Windows, and the served file is still corrupted.

I found that the AssetsController still uses response.outputStream to serve the file content, which does not specify the exact character encoding.

Here is a link related to a SO question: http://stackoverflow.com/questions/1992400/how-to-send-through-servletoutputstream-characters-in-utf-8-encoding

In issue #62 I have added the following code but it is not used in the plugin version 1.5.7:

  // if request encoding is specified, then server the content using 
  if (request.characterEncoding) {
    def w = response.writer
    w.write(assetFile)
    w.flush()
  } else {
    response.outputStream << assetFile
    response.flushBuffer()
}
@crystalcyril
Copy link
Author

Seems my solutions works on text files (e.g. JS, CSS) but not on image, I got error on the java.io.PrintWriter.write() method which does not accept byte objects.

I updated the checking as below:

if (response.characterEncoding && assetFile instanceof java.lang.String) {

@davydotcom
Copy link
Contributor

We bypass character encoding with outputStream as its a byteStream which has no encoding

@crystalcyril
Copy link
Author

I found that the AssetsController will serve two kinds of streams:

  1. binary stream
  2. character stream

For 1), it is true that no encoding is required, however for 2), character encoding is required.

I deployed the plugin version 1.5.7 on Windows and followed the instructions, however the Javascript is still not served properly. With the code modification above, both images (binary) and Javascript (character) are served properly.

Suggestion welcomed.

@davydotcom
Copy link
Contributor

Ok so I resolved this issue a bit differently. The assetProcessorService now always sends a byte stream not a String. This byte stream is now properly converted based on encoding passed. It should be available for use in 1.5.8

@crystalcyril
Copy link
Author

Oh it is ok too, as I found that it is a bit strange that it returns string while the definition of AssetFile seems not restricted to character stream.

@crystalcyril
Copy link
Author

I will test it tomorrow on my Windows machine and report whether it works.

@davydotcom
Copy link
Contributor

Yea cool thanks! Would love to get this out of the way before grails 2.4

@crystalcyril
Copy link
Author

I tried development mode and played with the configuration option "grails.assets.bundle = true/false" and both works when running "run-app" in Grails console.

Only thing I didn't test yet is in production mode (run-war as well as deployment in application server e.g. Tomcat/Jetty)

@davydotcom
Copy link
Contributor

Glad to hear it less concerned for production as that is entirely byte level

Sent from my iPhone

On Feb 20, 2014, at 9:51 PM, Cyril Poon notifications@github.com wrote:

I tried development mode and played with the configuration option "grails.assets.bundle = true/false" and both works when running "run-app" in Grails console.

Only thing I didn't test yet is in production mode (run-war as well as deployment in application server e.g. Tomcat/Jetty)


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants