Skip to content

Commit

Permalink
Raise unknown tag in deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Jan 7, 2021
1 parent e313c9c commit 0b504b7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ext/liquid_c/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ static ID
intern_parse,
intern_square_brackets,
intern_unknown_tag_in_liquid_tag,
intern_ivar_nodelist;
intern_ivar_nodelist,
intern_raise_unknown_tag;

static VALUE tag_registry;
static VALUE variable_placeholder = Qnil;
static VALUE cLiquidBlock;

typedef struct parse_context {
tokenizer_t *tokenizer;
Expand Down Expand Up @@ -375,7 +377,9 @@ static VALUE block_body_parse_from_serialize(block_body_t *body, VALUE tokenizer
VALUE markup = rb_utf8_str_new(tag_markup_header_markup(current_tag), current_tag->markup_len);

VALUE tag_class = rb_funcall(tag_registry, intern_square_brackets, 1, tag_name);
assert(RTEST(tag_class));
if (!RTEST(tag_class)) {
return rb_funcall(cLiquidBlock, intern_raise_unknown_tag, 4, tag_name, Qnil, Qnil, parse_context_obj);
}

serialize_parse_context_enter_tag(serialize_context, current_tag);
VALUE new_tag = rb_funcall(tag_class, intern_parse, 4,
Expand Down Expand Up @@ -700,13 +704,16 @@ void liquid_define_block_body()
intern_square_brackets = rb_intern("[]");
intern_unknown_tag_in_liquid_tag = rb_intern("unknown_tag_in_liquid_tag");
intern_ivar_nodelist = rb_intern("@nodelist");
intern_raise_unknown_tag = rb_intern("raise_unknown_tag");

tag_registry = rb_funcall(cLiquidTemplate, rb_intern("tags"), 0);
rb_global_variable(&tag_registry);

VALUE cLiquidCBlockBody = rb_define_class_under(mLiquidC, "BlockBody", rb_cObject);
rb_define_alloc_func(cLiquidCBlockBody, block_body_allocate);

cLiquidBlock = rb_const_get(mLiquid, rb_intern("Block"));

rb_define_method(cLiquidCBlockBody, "initialize", block_body_initialize, 1);
rb_define_method(cLiquidCBlockBody, "parse", block_body_parse, 2);
rb_define_method(cLiquidCBlockBody, "freeze", block_body_freeze, 0);
Expand Down

0 comments on commit 0b504b7

Please sign in to comment.