db296ff
--- alexandria-book-collection-manager-0.7.5/lib/alexandria/library_store.rb.broken_yaml	2020-05-11 16:39:20.000000000 +0900
db296ff
+++ alexandria-book-collection-manager-0.7.5/lib/alexandria/library_store.rb	2020-10-17 16:07:44.600805994 +0900
5cccbb5
@@ -48,8 +48,23 @@ module Alexandria
db296ff
         Dir["*" + Library::EXT[:book]].sort.each do |filename|
5cccbb5
           test[1] = filename if (test[0]).zero?
Mamoru Tasaka a04e982
 
Mamoru Tasaka a04e982
+          book_valid_p = true
Mamoru Tasaka a04e982
+
5cccbb5
           unless File.size? test[1]
5cccbb5
             log.warn { "Book file #{test[1]} was empty" }
Mamoru Tasaka a04e982
+            book_valid_p = false
Mamoru Tasaka a04e982
+          end
Mamoru Tasaka a04e982
+
Mamoru Tasaka a04e982
+          if book_valid_p
Mamoru Tasaka a04e982
+            begin
79794e9
+              book = regularize_book_from_yaml(test[1])
Mamoru Tasaka a04e982
+            rescue Psych::SyntaxError => e
Mamoru Tasaka a04e982
+              log.warn "Book file #{test[1]} could not be parsed"
Mamoru Tasaka a04e982
+              book_valid_p = false
Mamoru Tasaka a04e982
+            end
Mamoru Tasaka a04e982
+          end
Mamoru Tasaka a04e982
+
Mamoru Tasaka a04e982
+          if not book_valid_p
5cccbb5
             md = /([\dxX]{10,13})#{Library::EXT[:book]}/.match(filename)
Mamoru Tasaka a04e982
             if md
Mamoru Tasaka a04e982
               file_isbn = md[1]
5cccbb5
@@ -60,7 +75,7 @@ module Alexandria
Mamoru Tasaka a04e982
             end
Mamoru Tasaka a04e982
             next
Mamoru Tasaka a04e982
           end
5cccbb5
-          book = regularize_book_from_yaml(test[1])
Mamoru Tasaka a04e982
+
Mamoru Tasaka a04e982
           old_isbn = book.isbn
Mamoru Tasaka a04e982
           old_pub_year = book.publishing_year
Mamoru Tasaka a04e982
           begin
db296ff
@@ -181,6 +196,8 @@ module Alexandria
f697213
     private
f697213
 
f697213
     def regularize_book_from_yaml(name)
f697213
+      require 'syck/encoding'
f697213
+
f697213
       text = IO.read(name)
f697213
 
f697213
       # Code to remove the mystery string in books imported from Amazon
db296ff
@@ -203,7 +220,7 @@ module Alexandria
f697213
       end
Mamoru Tasaka a04e982
 
5cccbb5
       # TODO: Ensure book loading passes through Book#initialize
f697213
-      book = YAML.safe_load(text, permitted_classes: [Book, Time])
f697213
+      book = YAML.safe_load(Syck::unescape(text), permitted_classes: [Book, Time])
Mamoru Tasaka a04e982
 
Mamoru Tasaka a04e982
       unless book.isbn.class == String
Mamoru Tasaka a04e982
         # HACK