[alexandria/f17] Convert escaped characters in yaml file generated by ruby 18x to
Mamoru Tasaka
mtasaka at fedoraproject.org
Fri Apr 13 03:55:20 UTC 2012
commit 337909d3926e9f10c9b26becccc4e51d266b6159
Author: Mamoru TASAKA <mtasaka at localhost.localdomain>
Date: Fri Apr 13 12:55:12 2012 +0900
Convert escaped characters in yaml file generated by ruby 18x to
aviod garbage characters
- Fix crash when moving book entry to another library when the same
entry is found
alexandria-0.6.8-utf8-convert.patch | 65 +++++++++++++++++++++++++++++++++++
alexandria.spec | 18 +++++++++-
clog | 5 ++-
3 files changed, 86 insertions(+), 2 deletions(-)
---
diff --git a/alexandria-0.6.8-utf8-convert.patch b/alexandria-0.6.8-utf8-convert.patch
new file mode 100644
index 0000000..67a2de6
--- /dev/null
+++ b/alexandria-0.6.8-utf8-convert.patch
@@ -0,0 +1,65 @@
+--- alexandria-0.6.8/lib/alexandria/models/library.rb.ruby19_utf8 2009-12-07 05:16:57.000000000 +0900
++++ alexandria-0.6.8/lib/alexandria/models/library.rb 2012-04-13 12:38:05.065369194 +0900
+@@ -177,6 +177,25 @@
+ library
+ end
+
++ UNESCAPES = {
++ 'a' => "\x07", 'b' => "\x08", 't' => "\x09",
++ 'n' => "\x0a", 'v' => "\x0b", 'f' => "\x0c",
++ 'r' => "\x0d", 'e' => "\x1b", '\\' => '\\',
++ }
++
++ def self.unescape_yaml(value)
++ # From ruby 1.9.2
++ value.gsub( /\\(?:([nevfbart\\])|0?x([0-9a-fA-F]{2})|u([0-9a-fA-F]{4}))/ ) {
++ if $3
++ ["#$3".hex ].pack('U*')
++ elsif $2
++ [$2].pack( "H2" )
++ else
++ UNESCAPES[$1]
++ end
++ }
++ end
++
+ def self.regularize_book_from_yaml(name)
+ text = IO.read(name)
+
+@@ -198,7 +217,7 @@
+ new_yaml.sub!(/^\s*\-+\s*/, '')
+ text.sub!(md[0], "loaned_since: #{new_yaml}\n")
+ end
+- book = YAML.load(text)
++ book = YAML.load(unescape_yaml(text))
+ unless book.isbn.class == String
+ # HACK
+ md = /isbn: (.+)/.match(text)
+--- alexandria-0.6.8/lib/alexandria/ui/dialogs/misc_dialogs.rb.ruby19_utf8 2009-03-26 08:09:32.000000000 +0900
++++ alexandria-0.6.8/lib/alexandria/ui/dialogs/misc_dialogs.rb 2012-04-13 12:38:05.065369194 +0900
+@@ -22,9 +22,11 @@
+ GetText.bindtextdomain(Alexandria::TEXTDOMAIN, :charset => "UTF-8")
+
+ def initialize(parent, library, book)
++ # Don't know why, however force_encoding seems needed here to
++ # prevent crash...
+ super(parent,
+ _("The book '%s' already exists in '%s'. Would you like " +
+- "to replace it?") % [ book.title, library.name ],
++ "to replace it?") % [ book.title, library.name ].dup.map!{|str| str.force_encoding("UTF-8")},
+ Gtk::Stock::DIALOG_QUESTION,
+ [[_("_Skip"), Gtk::Dialog::RESPONSE_CANCEL],
+ [_("_Replace"), Gtk::Dialog::RESPONSE_OK]],
+--- alexandria-0.6.8/lib/alexandria/ui/ui_manager.rb.ruby19_utf8 2011-11-15 22:09:19.000000000 +0900
++++ alexandria-0.6.8/lib/alexandria/ui/ui_manager.rb 2012-04-13 12:38:05.066369229 +0900
+@@ -825,7 +825,9 @@
+ iter[Columns::TITLE] = book.title
+ title = book.title.sub(REDUCE_TITLE_REGEX, '\1...')
+ iter[Columns::TITLE_REDUCED] = title
+- iter[Columns::AUTHORS] = book.authors.join(', ')
++ # Don't know why, however force_encoding seems needed here to
++ # prevent crash...
++ iter[Columns::AUTHORS] = book.authors.dup.map!{|str| str.force_encoding("UTF-8")}.join(', ')
+ iter[Columns::ISBN] = book.isbn.to_s
+ iter[Columns::PUBLISHER] = book.publisher
+ iter[Columns::PUBLISH_DATE] = (book.publishing_year.to_s rescue "")
diff --git a/alexandria.spec b/alexandria.spec
index 26a721c..5369b3f 100644
--- a/alexandria.spec
+++ b/alexandria.spec
@@ -1,11 +1,15 @@
+%if 0%{?fedora} >= 17
+%define rubyabi 1.9.1
+%else
%define rubyabi 1.8
+%endif
%define repoid 75529
%define majorver 0.6.8
%undefine minorver
%undefine ifpre
-%define fedorarel 5
+%define fedorarel 6
%define rel %{?ifpre:0.}%{fedorarel}%{?minorver:.%minorver}
@@ -53,6 +57,11 @@ Patch16: alexandria-0.6.8-evalfix.patch
# With working zoom and ruby19, z3950 provider aborts
# with syntax error about next
Patch17: alexandria-0.6.8-z3950-next.patch
+# Two fixes:
+# a. loading yaml file generated by ruby 18x will show garbage characters
+# b. moving book entry to another library which also contains the
+# same book will cause crash..
+Patch18: alexandria-0.6.8-utf8-convert.patch
BuildArch: noarch
BuildRequires: ruby(abi) >= %{rubyabi}
@@ -120,6 +129,7 @@ Alexandria is a GNOME application to help you manage your book collection.
%patch15 -p1 -b .kcodefix
%patch16 -p1 -b .evalfix
%patch17 -p1 -b .z3950_next
+%patch18 -p1 -b .ruby19_utf8
# Embed Fedora EVR
%{__sed} -i.evr \
@@ -214,6 +224,12 @@ exit 0
%{_datadir}/icons/hicolor/*/apps/%{name}.*
%changelog
+* Fri Apr 13 2012 Mamoru Tasaka <mtasaka at fedoraproject.org> - 0.6.8-6
+- Convert escaped characters in yaml file generated by ruby 18x to
+ aviod garbage characters
+- Fix crash when moving book entry to another library when the same
+ entry is found
+
* Wed Apr 11 2012 Mamoru Tasaka <mtasaka at fedoraproject.org> - 0.6.8-5
- Fix crash on z3950 provider with working zoom
diff --git a/clog b/clog
index 9a0de9e..bbe34a5 100644
--- a/clog
+++ b/clog
@@ -1,2 +1,5 @@
-Fix crash on z3950 provider with working zoom
+Convert escaped characters in yaml file generated by ruby 18x to
+ aviod garbage characters
+- Fix crash when moving book entry to another library when the same
+ entry is found
More information about the scm-commits
mailing list