postmodern / ffi-hunspell

Ruby FFI bindings for Hunspell.
MIT License
48 stars 24 forks source link

Strings added to dictionary are sometimes modified in place #22

Open MaxLap opened 7 years ago

MaxLap commented 7 years ago

Using the en_US dict (en_CA and fr don't have this behavior), the passed string will sometimes be modified in place. It seems to happen when the string has a mix of upper and lower case letters. Here is an example:

de = FFI::Hunspell.dict 'en_US'
a = 'HEYGuys'
de.add(a)
puts a # => Heyguys

I have no idea if the other methods can also do such a things. As I said, this isn't happening on every dicts. My suggestion is to simply .dup the string that is passed to, at least, the add methods. (Note that to_s doesn't dup a string).

In the mean time, I simply .dup the strings myself before passing them to add to work around this issue.

MaxLap commented 7 years ago

Note, I just realized I had a similar problem elsewhere even using dup. I'm guessing ruby shared buffers behind the scene or something:

de = FFI::Hunspell.dict 'en_US'
a = 'StateMachine'
de.add(a)
puts a # => Statemachine

Instead of using dup, i use my_word + '', and that seems to solve my issue...

postmodern commented 7 years ago

I cannot reproduce this with ruby 2.3.4, ffi 1.9.18, and hunspell 1.4.1. What versions are you running?

MaxLap commented 7 years ago

I just tried and the problem still happens with the following: ffi 1.9.18, ruby 2.4.1, ffi-hunspell 0.4.0 and: "libhunspell-1.3-0:amd64 1.3.3-4ubuntu1" I am using on Ubuntu 16.04

I really don't think the libhunspell would be the reason...

Just to make sure, you are simply putting the following in a file and running it?

require 'ffi/hunspell'
de = FFI::Hunspell.dict 'en_US'
a = 'HEYGuys'
de.add(a)
puts a # => 'Heyguys', but this should be 'HEYGuys'

The output should be "HEYGuys", but for me at least, is "Heyguys"

Thanks for your time

MaxLap commented 7 years ago

I just realized that i typoed the version of ffi i tested with. (wrote 1.9.1), i edited it to the correct 1.9.18.