Fix the encoding error

fix the encoding error.
Added functional test case for issue #859

Added function test case for issue #859.