DAddYE / leveldb

LevelDB for Ruby (embedded)
http://daddye.it/leveldb
MIT License
126 stars 15 forks source link

Bug when using unicode #11

Closed gfodor closed 10 years ago

gfodor commented 11 years ago
2.0.0-p247 :001 > require "leveldb"                                                                                                          
 => true 
2.0.0-p247 :002 > db = LevelDB::DB.new("test.ldb")                                                                                           
 => #<LevelDB::DB:0x3fcd84c4be04> 
2.0.0-p247 :003 > db["foo Malmö bar"] = "biz Malmö baz"                                                                            
 => "biz Malmö baz" 
2.0.0-p247 :004 > db["foo Malmö bar"] 
 => "biz Malm\xC3\xB6 ba" # NOTE the missing "r" at the end, due to size != bytesize
2.0.0-p247 :005 > db["foo Malmö bar"] == "biz Malmö baz" # TEST
 => false 

The issue here I think stems from the fact that String#size is being used instead of String#bytesize in the code. By updating the code to use String#bytesize the issue of truncation seemed to go away looking at the string. However, the test (the last line of my irb session) still doesn't work. So I am certainly missing something wrt encoding but got stuck making further progress. Thanks!

usiegj00 commented 10 years ago

Fixed in: https://github.com/DAddYE/leveldb/pull/13