I have a cfinvoke:
<cfinvoke component="cfcs.people" method="getPerson">
<cfinvokeargument name="name" value="José">
</cfinvoke>
And a function:
<cffunction name="getPerson" access="remote" returntype="any">
<cfargument name="name" type="string">
<cfquery name="qry" datasource="#datasource#">
SELECT id
FROM people
WHERE name = <cfqueryparam value="#name#" cfsqltype="CF_SQL_NVARCHAR">
</cfquery>
<cfreturn qry>
</cffunction>
I have a row in the people
table with a name
of "José", however the cfinvoke does not return this row. Any name that does not contain a special character works, but any name with a special character returns no rows.
What is causing special characters to break the SELECT, and what can I do to fix it?
Try outputting only the literal string in a .cfm script
José
If the browser displays the mangled string below, then it is a file encoding problem, not an issue with cfinvoke
or cffunction
José
To resolve it, set the encoding to UTF-8 at the top of the script:
<cfprocessingdirective pageencoding="utf-8">
You can also change it globally, for the entire jvm, using the jvm arg -Dfile.encoding=UTF-8
.
It's worth noting cfprocessingdirective is frequently misunderstood. The only reason it's required here is because the literal string José
is embedded in the cfm source. If that string will ultimately be replaced with say a form field, then you won't need the directive. The original code will work without issue.
<!--- works in modern versions of CF -->
<cfinvoke component="cfcs.people" method="getPerson">
<cfinvokeargument name="name" value="#form.name#">
</cfinvoke>