Uploaded image for project: 'Railo'
  1. Railo
  2. RAILO-2096

RESTful web services do not correctly handle character encoding

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Out of Date
    • Affects Version/s: 4.0.0.013
    • Fix Version/s: None
    • Labels:
      None
    • Steps to Reproduce:
      Hide

      // Application.cfc
      component {

      this.name = "restEncodingTest";
      this.restSettings =

      { cfclocation = "services", skipCfcWithError = true }

      ;
      this.webAdminPassword = "123456"; // needed for Railo (which SUX)

      public void function onApplicationStart()

      { restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()) & "services", "services"); }

      }

      // Person.cfc

      component rest=true restPath="person" {

      pageencoding "UTF-8";

      remote query function getAsXml(required numeric id restargsource="path") httpmethod="get" restpath="

      {id}" produces="text/xml" { return getData(id); }

      remote query function getAsJson(required numeric id restargsource="path") httpmethod="get" restpath="{id}

      " produces="application/json"

      { return getData(id); }

      private query function getData(required numeric id)

      { return queryNew( "id,lastName,firstName", "Integer,Varchar,Varchar", [[#arguments.id#, "Chabal", "Sébastien"]] ); }

      }

      <!---getPerson.cfm --->
      <cfset id = randRange(1,1000)>
      <cfhttp method="get" url="http://localhost:8500/rest/services/person/#id#" result="xmlResponse" charset="UTF-8">
      <cfhttpparam type="header" name="accept" value="text/xml">
      </cfhttp>
      <cfhttp method="get" url="http://localhost:8500/rest/services/person/#id#" result="jsonResponse" charset="UTF-8">
      <cfhttpparam type="header" name="accept" value="application/json">
      </cfhttp>

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="utf-8">
      <title></title>
      </head>
      <body>
      <cfoutput>
      <h2>XML</h2>
      Raw: #xmlResponse.filecontent#<br />
      Escaped: #htmlEditFormat(xmlResponse.filecontent)#<br />
      Parsed:
      <cfdump var="#xmlParse(xmlResponse.filecontent)#">

      <h2>JSON</h2>
      Raw: #jsonResponse.filecontent#<br />
      Deserialised:
      <cfdump var="#deserializeJson(jsonResponse.filecontent)#">
      </cfoutput>
      </body>
      </html>

      <!---standardRemoteCall.cfm --->
      <cfset id = randRange(1,1000)>
      <cfhttp method="get" url="http://localhost:8500/shared/CF/rest/encoding/services/Person.cfc?method=getAsXml&id=#id#" result="response">

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="utf-8">
      <title></title>
      </head>
      <body>
      <cfoutput>#htmlEditFormat(response.filecontent)#</cfoutput>
      </body>
      </html>

      Show
      // Application.cfc component { this.name = "restEncodingTest"; this.restSettings = { cfclocation = "services", skipCfcWithError = true } ; this.webAdminPassword = "123456"; // needed for Railo (which SUX) public void function onApplicationStart() { restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()) & "services", "services"); } } // Person.cfc component rest=true restPath="person" { pageencoding "UTF-8"; remote query function getAsXml(required numeric id restargsource="path") httpmethod="get" restpath=" {id}" produces="text/xml" { return getData(id); } remote query function getAsJson(required numeric id restargsource="path") httpmethod="get" restpath="{id} " produces="application/json" { return getData(id); } private query function getData(required numeric id) { return queryNew( "id,lastName,firstName", "Integer,Varchar,Varchar", [[#arguments.id#, "Chabal", "Sébastien"]] ); } } <!---getPerson.cfm ---> <cfset id = randRange(1,1000)> <cfhttp method="get" url="http://localhost:8500/rest/services/person/#id#" result="xmlResponse" charset="UTF-8"> <cfhttpparam type="header" name="accept" value="text/xml"> </cfhttp> <cfhttp method="get" url="http://localhost:8500/rest/services/person/#id#" result="jsonResponse" charset="UTF-8"> <cfhttpparam type="header" name="accept" value="application/json"> </cfhttp> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> </head> <body> <cfoutput> <h2>XML</h2> Raw: #xmlResponse.filecontent#<br /> Escaped: #htmlEditFormat(xmlResponse.filecontent)#<br /> Parsed: <cfdump var="#xmlParse(xmlResponse.filecontent)#"> <h2>JSON</h2> Raw: #jsonResponse.filecontent#<br /> Deserialised: <cfdump var="#deserializeJson(jsonResponse.filecontent)#"> </cfoutput> </body> </html> <!---standardRemoteCall.cfm ---> <cfset id = randRange(1,1000)> <cfhttp method="get" url="http://localhost:8500/shared/CF/rest/encoding/services/Person.cfc?method=getAsXml&id=#id#" result="response"> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title></title> </head> <body> <cfoutput>#htmlEditFormat(response.filecontent)#</cfoutput> </body> </html>

      Description

      Problem Description:
      See http://adamcameroncoldfusion.blogspot.co.uk/2012/10/probable-significant-bug-in-coldfusion.html

      Summary: REST responses do not correctly encode the data being returned, ie: data that should be ITF-8 encoded is not.

      Steps to Reproduce:
      See http://adamcameroncoldfusion.blogspot.co.uk/2012/10/probable-significant-bug-in-coldfusion.html

      Actual Result:
      See http://adamcameroncoldfusion.blogspot.co.uk/2012/10/probable-significant-bug-in-coldfusion.html

      Output from test files:
      XML

      Raw:732ChabalS�bastien
      Escaped: <QUERY ID="1"><COLUMNNAMES><COLUMN NAME="id"></COLUMN><COLUMN NAME="lastName"></COLUMN><COLUMN NAME="firstName"></COLUMN></COLUMNNAMES><ROWS><ROW><COLUMN TYPE="NUMBER">732</COLUMN><COLUMN TYPE="STRING">Chabal</COLUMN><COLUMN TYPE="STRING">S�bastien</COLUMN></ROW></ROWS></QUERY>
      Parsed:
      xml document
      JSON

      Raw:

      {"COLUMNS":["ID","LASTNAME","FIRSTNAME"],"DATA":[[732,"Chabal","S�bastien"]]}

      Deserialised:
      struct
      COLUMNS
      DATA
      array
      1
      array
      1 732
      2 Chabal
      3 S�bastien
      4

      Control:

      <wddxPacket version='1.0'><header/><data><recordset rowCount='1' fieldNames='id,lastName,firstName' type='coldfusion.sql.QueryTable'><field name='id'><number>673.0</number></field><field name='lastName'><string>Chabal</string></field><field name='firstName'><string>Sébastien</string></field></recordset></data></wddxPacket>

      Expected Result:
      For it to work properly.

      Any Workarounds:
      No, none.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                micstriit Michael Offner
                Reporter:
                adamcameroncf Adam Cameron
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: