In a Rails 3.2 app (Ruby 1.9.2) I am getting the following errors
A PGError occurred in mobile_users#update:
incomplete multibyte character
These are Postgres errors bu I get similar SQLIte error when testing in dev and test modes
The params that cause this error are (auth token deliberately omitted)
* Parameters: {"mobile_user"=>{"quiz_id"=>"1", "auth"=>"xxx", "name"=>"Joaqu\xEDn"}, "action"=>"update", "controller"=>"mobile_users", "id"=>"1", "format"=>"mobile"}
This is coming in as a JSON HTTP Put request and the update action dealing with this is as follows
# PUT /mobile_users/1
# PUT /mobile_users/1.xml
def update
@mobile_user = current_mobile_user
@mobile_user.attributes = params[:mobile_user]
respond_to do |format|
if @mobile_user.save
format.html { redirect_to(@mobile_user, :notice => 'Mobile user was successfully updated.') }
format.json { head :ok }
format.mobile { head :ok }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @mobile_user.errors, :status => :unprocessable_entity }
format.mobile { render :json => @mobile_user.errors, :status => :unprocessable_entity }
format.xml { render :xml => @mobile_user.errors, :status => :unprocessable_entity }
end
end
end
The offending string is in the above params is "Joaqu\xEDn" which is perfectly valid. the thing is that I need to handle all character sets from any language.
I assume I would need to use the iconv library but in order to do that I would need to detect the character set to convert to UTF8 from and I haven't a clue how to do this.
I am also getting invalid byte sequence in UTF-8 for "name"=>"p\xEDa "