Mantis - Quercus
Viewing Issue Advanced Details
5328 minor always 01-10-13 02:58 01-11-13 14:48
ngoc  
nam  
normal  
closed  
fixed  
none    
none 4.0.34  
0005328: Scripting utf-8 output vietnamese incorrect
this bug is reported at : http://bugs.caucho.com/view.php?id=5308 [^]
but status is fixed , but i can't output correct vietnamese character (UTF-8)

Quercus quercus = new Quercus();
          quercus.setUnicodeSemantics(true);
          quercus.setIni("unicode.semantics", "on");
          quercus.init();
          quercus.start();
          QuercusScriptEngine engine = new QuercusScriptEngine(new QuercusScriptEngineFactory(), quercus);
          String sayHelloVN = "<h1>Xin chào chó &0000273;&7891;</h1>";
        
        try {
            System.out.println(sayHelloVN);
            engine.eval( sayHelloVN);
                    
        } catch (Exception e) {
        
            e.printStackTrace();
        }

Notes
(0006151)
ngoc   
01-10-13 03:03   
oop !!! sample code not display correct .
see at
http://pastebin.com/eknPAyuy [^]
(0006156)
nam   
01-11-13 14:48   
php/2127
php/2128

Fixed for 4.0.34. To verify, please use subversion to check out our sources.

The following are now set by default: unicode.semantics=on and scriptEncoding=utf8. And QuercusScriptEngine returns Quercus value types now (return type of eval() is Value).

import java.io.*;
import javax.script.*;

import com.caucho.quercus.env.*;
import com.caucho.quercus.script.*;

public class Test
{
  public static void main(String[] args)
    throws Exception
  {
    boolean isUnicodeSemantics = true;

    QuercusScriptEngine phpEngine
      = new QuercusScriptEngine(isUnicodeSemantics);

    StringWriter writer = new StringWriter();
    ScriptContext context = phpEngine.getContext();
    context.setWriter(writer);

    String a0 = "ä";
    String a1 = "\u00e4";
    String code = "<?php print '" + a1 + "'; return '" + a1 + "'; ?>&
quot;;

    Object obj = phpEngine.eval(code);
    String returnValue = obj.toString();
      
    System.out.println("a0_umlaut : " + a0 + ",length=" + a0.length() + ",h
ex(0)=" + Integer.toHexString(a0.charAt(0)));
    System.out.println("a1_umlaut : " + a1 + ",length=" + a1.length() + ",h
ex(0)=" + Integer.toHexString(a1.charAt(0)));

    System.out.println("code      : " + code);
    System.out.println("return    : " + returnValue + ",length=" + returnValue.l
ength() + ",hex(0)=" + Integer.toHexString(returnValue.charAt(0)));

    String output = writer.getBuffer().toString();
    System.out.println("output    : " + output + ",length=" + output.length() + 
",hex(0)=" + Integer.toHexString(output.charAt(0)));
  }
}