summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb2
-rw-r--r--ext/syck/lib/syck/rubytypes.rb2
-rw-r--r--lib/rdoc/parser.rb4
-rw-r--r--string.c13
-rw-r--r--test/ruby/test_string.rb1
6 files changed, 22 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index c0dfdf4340..261444a13e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Aug 31 03:42:14 2010 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * string.c (tr_setup_table): fix bug in r29146.
+ Initialize table even if cflag is 0; tr_find see whether
+ del is empty or not.
+
+ * string.c (tr_find): nodel can't be NULL; if NULL, it means
+ it is not specified.
+
Mon Aug 30 21:29:21 2010 Tanaka Akira <akr@fsij.org>
* ext/pathname/pathname.c (path_executable_real_p):
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 520cd7e9c2..6df1151ad7 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -205,7 +205,7 @@ module Psych
quote = false
style = Nodes::Scalar::ANY
- if o.index("\x00") || o.count("^ -~\t\r\n").fdiv(o.length) > 0.3
+ if o.index("\x00") || o.count("\x00-\x7F", "^ -~\t\r\n").fdiv(o.length) > 0.3
str = [o].pack('m').chomp
tag = '!binary' # FIXME: change to below when syck is removed
#tag = 'tag:yaml.org,2002:binary'
diff --git a/ext/syck/lib/syck/rubytypes.rb b/ext/syck/lib/syck/rubytypes.rb
index 50a6f4622b..f8bbfea022 100644
--- a/ext/syck/lib/syck/rubytypes.rb
+++ b/ext/syck/lib/syck/rubytypes.rb
@@ -148,7 +148,7 @@ class String
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
end
def is_binary_data?
- self.count("^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
+ self.count("\x00-\x7F", "^ -~\t\r\n").fdiv(self.size) > 0.3 || self.index("\x00") unless self.empty?
end
def String.yaml_new( klass, tag, val )
val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb
index 9cfda127d9..1e4ab7c7a4 100644
--- a/lib/rdoc/parser.rb
+++ b/lib/rdoc/parser.rb
@@ -76,9 +76,9 @@ class RDoc::Parser
elsif s.scan(/<%|%>/).length >= 4 || s.index("\x00") then
true
elsif 0.respond_to? :fdiv then
- s.count("^ -~\t\r\n").fdiv(s.size) > 0.3
+ s.count("\x00-\x7F", "^ -~\t\r\n").fdiv(s.size) > 0.3
else # HACK 1.8.6
- (s.count("^ -~\t\r\n").to_f / s.size) > 0.3
+ (s.count("\x00-\x7F", "^ -~\t\r\n").to_f / s.size) > 0.3
end
end
diff --git a/string.c b/string.c
index 5c80903ade..1b1dc62724 100644
--- a/string.c
+++ b/string.c
@@ -5095,6 +5095,11 @@ tr_setup_table(VALUE str, char stable[256], int first,
ptable = *ctablep;
*ctablep = table;
}
+ else {
+ table = rb_hash_new();
+ ptable = *tablep;
+ *tablep = table;
+ }
if (first) {
for (i=0; i<256; i++) {
stable[i] = 1;
@@ -5113,10 +5118,8 @@ tr_setup_table(VALUE str, char stable[256], int first,
if (!table) {
table = rb_hash_new();
- if (!cflag) {
- ptable = *tablep;
- *tablep = table;
- }
+ ptable = *tablep;
+ *tablep = table;
}
if (!ptable || !NIL_P(rb_hash_aref(ptable, key))) {
rb_hash_aset(table, key, Qtrue);
@@ -5144,7 +5147,7 @@ tr_find(unsigned int c, char table[256], VALUE del, VALUE nodel)
return TRUE;
}
}
- else if (!nodel || NIL_P(rb_hash_lookup(nodel, v))) {
+ else if (nodel && NIL_P(rb_hash_lookup(nodel, v))) {
return TRUE;
}
return FALSE;
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index f28c1c84e7..ce90c1e8d7 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -502,6 +502,7 @@ class TestString < Test::Unit::TestCase
assert_equal(false, "a\u3041\u3042".tr("\u3041", "a").ascii_only?)
assert_equal("a", "abc\u{3042 3044 3046}".delete("^a"))
+ assert_equal("bc\u{3042 3044 3046}", "abc\u{3042 3044 3046}".delete("a"))
assert_equal("\u3042", "abc\u{3042 3044 3046}".delete("^\u3042"))
end