ri_cal 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.5.2
2
+ * Fixed http://rick_denatale.lighthouseapp.com/projects/30941/tickets/11
3
+ Export folding is not UTF-8 Safe
1
4
  === 0.5.1
2
5
  * Fixed README to acknowledge release on RubyForge
3
6
  === 0.5.0 rubyforge release candidate Tue May 26 10:26:43 2009 -0400
data/lib/ri_cal.rb CHANGED
@@ -11,7 +11,7 @@ module RiCal
11
11
  autoload :OccurrenceEnumerator, "#{my_dir}/ri_cal/occurrence_enumerator.rb"
12
12
 
13
13
  # :stopdoc:
14
- VERSION = '0.5.1'
14
+ VERSION = '0.5.2'
15
15
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
16
16
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
17
17
 
@@ -172,13 +172,32 @@ module RiCal
172
172
  def string #:nodoc:
173
173
  stream.string
174
174
  end
175
+
176
+ def valid_utf8?(string)
177
+ string.unpack("U") rescue nil
178
+ end
179
+
180
+ def utf8_safe_split(string, n)
181
+ if string.length <= n
182
+ [string, nil]
183
+ else
184
+ before = string[0, n]
185
+ after = string[n..-1]
186
+ until valid_utf8?(after)
187
+ n = n - 1
188
+ before = string[0, n]
189
+ after = string[n..-1]
190
+ end
191
+ [before, after.empty? ? nil : after]
192
+ end
193
+ end
175
194
 
176
195
  def fold(string) #:nodoc:
177
- stream.puts(string[0,73])
178
- string = string[73..-1]
179
- while string
180
- stream.puts " #{string[0, 72]}"
181
- string = string[72..-1]
196
+ line, remainder = *utf8_safe_split(string, 73)
197
+ stream.puts(line)
198
+ while remainder
199
+ line, remainder = *utf8_safe_split(remainder, 72)
200
+ stream.puts(" #{line}")
182
201
  end
183
202
  end
184
203
 
data/ri_cal.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ri_cal}
5
- s.version = "0.5.1"
5
+ s.version = "0.5.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["author=Rick DeNatale"]
9
- s.date = %q{2009-05-26}
9
+ s.date = %q{2009-05-28}
10
10
  s.default_executable = %q{ri_cal}
11
11
  s.description = %q{A new Ruby implementation of RFC2445 iCalendar.
12
12
 
@@ -51,4 +51,37 @@ describe RiCal::Component::Calendar do
51
51
  @it.export.should_not match(%r{X-RICAL-TZSOURCE=TZINFO:})
52
52
  end
53
53
  end
54
+
55
+ describe RiCal::Component::Calendar::FoldingStream do
56
+ before(:each) do
57
+ @it = RiCal::Component::Calendar::FoldingStream.new(nil)
58
+ end
59
+
60
+ describe "#utf_safe_split" do
61
+ it "should properly split an ascii string" do
62
+ @it.utf8_safe_split("abcdef", 3).should == ["abc", "def"]
63
+ end
64
+
65
+ it "should return a nil remainder if the string has less than n characters" do
66
+ @it.utf8_safe_split("a",2).should == ["a", nil]
67
+ end
68
+
69
+ it "should return a nil remainder if the string has exactly n characters" do
70
+ @it.utf8_safe_split("ab",2).should == ["ab", nil]
71
+ end
72
+
73
+ it "should not split a 2-byte utf character" do
74
+ @it.utf8_safe_split("Café", 3).should == ["Caf", "é"]
75
+ @it.utf8_safe_split("Café", 4).should == ["Caf", "é"]
76
+ @it.utf8_safe_split("Café", 5).should == ["Café", nil]
77
+ end
78
+
79
+ it "should not split a 3-byte utf character" do
80
+ @it.utf8_safe_split("Prix €200", 5).should == ["Prix ", "€200"]
81
+ @it.utf8_safe_split("Prix €200", 6).should == ["Prix ", "€200"]
82
+ @it.utf8_safe_split("Prix €200", 7).should == ["Prix ", "€200"]
83
+ @it.utf8_safe_split("Prix €200", 8).should == ["Prix €", "200"]
84
+ end
85
+ end
86
+ end
54
87
  end
@@ -460,6 +460,13 @@ describe RiCal::Component::Event do
460
460
  export_string.should match(%r(^ following Michael's suggestion\\, let's meet at the food court at Crossr$))
461
461
  export_string.should match(%r(^ oads:\\nhttp://www\.shopcrossroadsplaza.c\.\.\.\\n$))
462
462
  end
463
+
464
+ it "should properly fold on export when the description contains multi-byte UTF-8 Characters" do
465
+ @it.description = "Juin 2009 <<Alliance Francaise Reunion>> lieu Café périferôl"
466
+ export_string = @it.export
467
+ export_string.should match(%r(^DESCRIPTION:Juin 2009 <<Alliance Francaise Reunion>> lieu Café périfer$))
468
+ export_string.should match(%r(^ ôl$))
469
+ end
463
470
  end
464
471
 
465
472
  if RiCal::TimeWithZone
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ri_cal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - author=Rick DeNatale
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-26 00:00:00 -04:00
12
+ date: 2009-05-28 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency