--- alexandria-0.6.8/lib/alexandria/models/library.rb.broken_yaml 2009-12-07 05:16:57.000000000 +0900
+++ alexandria-0.6.8/lib/alexandria/models/library.rb 2012-10-13 03:25:24.000000000 +0900
@@ -78,8 +78,23 @@
test[1] = filename if test[0] == 0
+ book_valid_p = true
+
if not File.size? test[1]
log.warn { "Book file #{test[1]} was empty"}
+ book_valid_p = false
+ end
+
+ if book_valid_p
+ begin
+ book = self.regularize_book_from_yaml(test[1])
+ rescue Psych::SyntaxError => e
+ log.warn "Book file #{test[1]} could not be parsed"
+ book_valid_p = false
+ end
+ end
+
+ if not book_valid_p
md = /([\dxX]{10,13})#{EXT[:book]}/.match(filename)
if md
file_isbn = md[1]
@@ -90,7 +105,7 @@
end
next
end
- book = self.regularize_book_from_yaml(test[1])
+
old_isbn = book.isbn
old_pub_year = book.publishing_year
begin
@@ -178,6 +193,8 @@
end
def self.regularize_book_from_yaml(name)
+ require 'syck/encoding'
+
text = IO.read(name)
#Code to remove the mystery string in books imported from Amazon
@@ -198,7 +215,7 @@
new_yaml.sub!(/^\s*\-+\s*/, '')
text.sub!(md[0], "loaned_since: #{new_yaml}\n")
end
- book = YAML.load(text)
+ book = YAML.load(Syck::unescape(text))
unless book.isbn.class == String
# HACK
md = /isbn: (.+)/.match(text)