2
2
3
3
VALUE cNokogiriXmlSaxParserContext ;
4
4
5
+ static ID id_read ;
6
+
5
7
static void
6
8
deallocate (xmlParserCtxtPtr ctxt )
7
9
{
@@ -26,6 +28,10 @@ parse_io(VALUE klass, VALUE io, VALUE encoding)
26
28
xmlParserCtxtPtr ctxt ;
27
29
xmlCharEncoding enc = (xmlCharEncoding )NUM2INT (encoding );
28
30
31
+ if (!rb_respond_to (io , id_read )) {
32
+ rb_raise (rb_eTypeError , "argument expected to respond to :read" );
33
+ }
34
+
29
35
ctxt = xmlCreateIOParserCtxt (NULL , NULL ,
30
36
(xmlInputReadCallback )noko_io_read ,
31
37
(xmlInputCloseCallback )noko_io_close ,
@@ -62,9 +68,8 @@ parse_memory(VALUE klass, VALUE data)
62
68
{
63
69
xmlParserCtxtPtr ctxt ;
64
70
65
- if (NIL_P (data )) {
66
- rb_raise (rb_eArgError , "data cannot be nil" );
67
- }
71
+ Check_Type (data , T_STRING );
72
+
68
73
if (!(int )RSTRING_LEN (data )) {
69
74
rb_raise (rb_eRuntimeError , "data cannot be empty" );
70
75
}
@@ -278,4 +283,6 @@ noko_init_xml_sax_parser_context()
278
283
rb_define_method (cNokogiriXmlSaxParserContext , "recovery" , get_recovery , 0 );
279
284
rb_define_method (cNokogiriXmlSaxParserContext , "line" , line , 0 );
280
285
rb_define_method (cNokogiriXmlSaxParserContext , "column" , column , 0 );
286
+
287
+ id_read = rb_intern ("read" );
281
288
}
0 commit comments