Permalink
Browse files

Make PostgreSQL array parser handle string encodings correctly on rub…

…y 1.9, bump version to 1.6.1

This copies the encoding of the embedded array string to each member
of the array.  It simplifies the logic somewhat, and also marks each
string as tainted, similar to the default logic to retrieve values.
  • Loading branch information...
1 parent 4a28f6f commit ff15ead5b660160bffa5a6ccaf883f2f57a89b63 @jeremyevans committed Oct 25, 2012
Showing with 32 additions and 11 deletions.
  1. +4 −0 CHANGELOG
  2. +27 −10 ext/sequel_pg/sequel_pg.c
  3. +1 −1 sequel_pg.gemspec
View
@@ -1,3 +1,7 @@
+=== 1.6.1 (2012-10-25)
+
+* Make PostgreSQL array parser handle string encodings correctly on ruby 1.9 (jeremyevans)
+
=== 1.6.0 (2012-09-04)
* Replace PQsetRowProcessor streaming with PQsetSingleRowMode streaming introduced in PostgreSQL 9.2beta3 (jeremyevans)
@@ -120,7 +120,11 @@ static int enc_get_index(VALUE val)
}
#endif
-static VALUE read_array(int *index, char *c_pg_array_string, int array_string_length, char *word, VALUE converter)
+static VALUE read_array(int *index, char *c_pg_array_string, int array_string_length, char *word, VALUE converter
+#ifdef SPG_ENCODING
+, int enc_index
+#endif
+)
{
int word_index = 0;
@@ -161,15 +165,20 @@ static VALUE read_array(int *index, char *c_pg_array_string, int array_string_le
{
rb_ary_push(array, Qnil);
}
- else if (RTEST(converter))
+ else
{
- VALUE rword = rb_str_new(word, word_index);
+ VALUE rword = rb_tainted_str_new(word, word_index);
RB_GC_GUARD(rword);
- rb_ary_push(array, rb_funcall(converter, spg_id_call, 1, rword));
- }
- else
- {
- rb_ary_push(array, rb_str_new(word, word_index));
+
+#ifdef SPG_ENCODING
+ rb_enc_associate_index(rword, enc_index);
+#endif
+
+ if (RTEST(converter)) {
+ rword = rb_funcall(converter, spg_id_call, 1, rword);
+ }
+
+ rb_ary_push(array, rword);
}
}
if(c == '}')
@@ -187,7 +196,11 @@ static VALUE read_array(int *index, char *c_pg_array_string, int array_string_le
else if(c == '{')
{
(*index)++;
- rb_ary_push(array, read_array(index, c_pg_array_string, array_string_length, word, converter));
+ rb_ary_push(array, read_array(index, c_pg_array_string, array_string_length, word, converter
+#ifdef SPG_ENCODING
+, enc_index
+#endif
+ ));
escapeNext = 1;
}
else
@@ -230,7 +243,11 @@ static VALUE parse_pg_array(VALUE self, VALUE pg_array_string, VALUE converter)
char *word = RSTRING_PTR(buf);
int index = 1;
- return read_array(&index, c_pg_array_string, array_string_length, word, converter);
+ return read_array(&index, c_pg_array_string, array_string_length, word, converter
+#ifdef SPG_ENCODING
+, enc_get_index(pg_array_string)
+#endif
+ );
}
static VALUE spg_time(const char *s) {
View
@@ -1,6 +1,6 @@
SEQUEL_PG_GEMSPEC = Gem::Specification.new do |s|
s.name = 'sequel_pg'
- s.version = '1.6.0'
+ s.version = '1.6.1'
s.platform = Gem::Platform::RUBY
s.has_rdoc = false
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "MIT-LICENSE"]

0 comments on commit ff15ead

Please sign in to comment.