Skip to content

Commit

Permalink
Check for UTF-8 strings on 1.9.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Dec 13, 2011
1 parent 12e693c commit d5f9811
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ext/redcarpet/rc_markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,26 @@ static VALUE rb_redcarpet_md__new(int argc, VALUE *argv, VALUE klass)
return rb_markdown;
}

static void check_utf8_encoding(VALUE str)
{
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *enc = rb_enc_get(str);
if (enc != rb_utf8_encoding() && enc != rb_usascii_encoding()) {
rb_raise(rb_eTypeError,
"Input must be UTF-8 or US-ASCII, %s given", rb_enc_name(enc));
}
#endif
}


static VALUE rb_redcarpet_md_render(VALUE self, VALUE text)
{
VALUE rb_rndr;
struct buf *output_buf;
struct sd_markdown *markdown;

Check_Type(text, T_STRING);
check_utf8_encoding(text);

rb_rndr = rb_iv_get(self, "@renderer");
Data_Get_Struct(self, struct sd_markdown, markdown);
Expand Down

0 comments on commit d5f9811

Please sign in to comment.