inukshuk / bibtex-ruby

A BibTeX library, parser, and converter for Ruby.
http://inukshuk.github.com/bibtex-ruby
GNU General Public License v3.0
156 stars 31 forks source link

`convert` modifies name fields from parsed entries #118

Closed RubenVerborgh closed 8 years ago

RubenVerborgh commented 8 years ago

The convert method, as opposed to convert!, is not supposed to modify an entry. Even though there is a test for this, it fails when fields of the entry are set through parsing instead of directly:

entry = BibTeX.parse('@book{o, author = {M\\"{o}by Dick} }')[0]
# entry.author = entry.author.to_s # workaround for the bug

puts entry[:author] # writes M\\"{o}by Dick
entry.convert :latex
puts entry[:author] # writes Möby Dick, but expected to be M\\"{o}by Dick

Below is a suggested unit test to place after the current test (but a fix went too deep into the internals for me):

it 'does not change the author of a parsed entry' do
  entry = BibTeX.parse('@book{o, author = {M\\"{o}by Dick}}')[0]
  e = entry.convert(:latex)
  e.wont_be :==, entry
  e.author.to_s.length.must_be :<, entry.author.to_s.length
end
inukshuk commented 8 years ago

Aw, thanks, that was pretty big -- name variables were not duplicated correctly (so the actual string used for the name parts stayed the same). The existing test worked because the title variable was a string value (where duplication worked). Good find!

Should be fixed in 4.4.1

RubenVerborgh commented 8 years ago

Thanks a lot!