Enforce ILLEGAL_CHILD
This commit is contained in:
parent
f8f884373f
commit
f73cb82cd1
|
@ -80,13 +80,9 @@ void hbr_blacklistchildren_init(void) {
|
|||
nh_map_str_strset_set(hbr_blacklistchildren_map, "video", video);
|
||||
}
|
||||
|
||||
int hbr_blacklistchildren_check(hb_char_t *parent) {
|
||||
return nh_map_str_strset_has(hbr_blacklistchildren_map, (char *) parent);
|
||||
}
|
||||
|
||||
int hbr_blacklistchildren_has(hb_char_t *parent, hb_char_t *child) {
|
||||
int hbr_blacklistchildren_allowed(hb_char_t *parent, hb_char_t *child) {
|
||||
nh_set_str_t set = nh_map_str_strset_get(hbr_blacklistchildren_map, (char *) parent, NULL);
|
||||
return nh_set_str_has(set, (char *) child);
|
||||
return set == NULL || !nh_set_str_has(set, (char *) child);
|
||||
}
|
||||
|
||||
#endif // _HDR_HYPERBUILD_RULE_BLACKLISTCHILDREN
|
||||
|
|
|
@ -10,13 +10,9 @@ void hbr_blacklistparents_init(void) {
|
|||
hbr_blacklistparents_map = nh_map_str_strset_create();
|
||||
}
|
||||
|
||||
int hbr_blacklistparents_check(hb_char_t *child) {
|
||||
return nh_map_str_strset_has(hbr_blacklistparents_map, (char *) child);
|
||||
}
|
||||
|
||||
int hbr_blacklistparents_has(hb_char_t *child, hb_char_t *parent) {
|
||||
int hbr_blacklistparents_allowed(hb_char_t *child, hb_char_t *parent) {
|
||||
nh_set_str_t set = nh_map_str_strset_get(hbr_blacklistparents_map, (char *) child, NULL);
|
||||
return nh_set_str_has(set, (char *) parent);
|
||||
return set == NULL || !nh_set_str_has(set, (char *) parent);
|
||||
}
|
||||
|
||||
#endif // _HDR_HYPERBUILD_RULE_BLACKLISTPARENTS
|
||||
|
|
|
@ -93,13 +93,9 @@ void hbr_whitelistchildren_init(void) {
|
|||
nh_map_str_strset_set(hbr_whitelistchildren_map, "ul", ul);
|
||||
}
|
||||
|
||||
int hbr_whitelistchildren_check(hb_char_t *parent) {
|
||||
return nh_map_str_strset_has(hbr_whitelistchildren_map, (char *) parent);
|
||||
}
|
||||
|
||||
int hbr_whitelistchildren_has(hb_char_t *parent, hb_char_t *child) {
|
||||
int hbr_whitelistchildren_allowed(hb_char_t *parent, hb_char_t *child) {
|
||||
nh_set_str_t set = nh_map_str_strset_get(hbr_whitelistchildren_map, (char *) parent, NULL);
|
||||
return nh_set_str_has(set, (char *) child);
|
||||
return set == NULL || nh_set_str_has(set, (char *) child);
|
||||
}
|
||||
|
||||
#endif // _HDR_HYPERBUILD_RULE_WHITELISTCHILDREN
|
||||
|
|
|
@ -138,13 +138,9 @@ void hbr_whitelistparents_init(void) {
|
|||
// Should be <body>, <frameset>, <head>, <dl>, <colgroup>, but ignoring
|
||||
}
|
||||
|
||||
int hbr_whitelistparents_check(hb_char_t *child) {
|
||||
return nh_map_str_strset_has(hbr_whitelistparents_map, (char *) child);
|
||||
}
|
||||
|
||||
int hbr_whitelistparents_has(hb_char_t *child, hb_char_t *parent) {
|
||||
int hbr_whitelistparents_allowed(hb_char_t *child, hb_char_t *parent) {
|
||||
nh_set_str_t set = nh_map_str_strset_get(hbr_whitelistparents_map, (char *) child, NULL);
|
||||
return nh_set_str_has(set, (char *) parent);
|
||||
return set == NULL || nh_set_str_has(set, (char *) parent);
|
||||
}
|
||||
|
||||
#endif // _HDR_HYPERBUILD_RULE_WHITELISTPARENTS
|
||||
|
|
|
@ -123,7 +123,7 @@ void hbs_content(hbs_options_t so, hbu_pipe_t pipe, hb_char_t *parent) {
|
|||
break;
|
||||
|
||||
case HBS_CONTENT_NEXT_STATE_OPENING_TAG:
|
||||
hbs_tag(so, pipe);
|
||||
hbs_tag(so, pipe, parent);
|
||||
break;
|
||||
|
||||
case HBS_CONTENT_NEXT_STATE_ENTITY:
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
|
||||
#include "../rule/char/whitespace.c"
|
||||
#include "../rule/tag/voidtags.c"
|
||||
#include "../rule/relation/blacklistchildren.c"
|
||||
#include "../rule/relation/blacklistparents.c"
|
||||
#include "../rule/relation/whitelistchildren.c"
|
||||
#include "../rule/relation/whitelistparents.c"
|
||||
|
||||
#include "../util/hbchar.h"
|
||||
#include "../util/pipe.c"
|
||||
|
@ -15,12 +19,13 @@
|
|||
#include "./helper/style.c"
|
||||
|
||||
// Declare first before content.c, as content.c depends on it
|
||||
void hbs_tag(hbs_options_t so, hbu_pipe_t pipe);
|
||||
void hbs_tag(hbs_options_t so, hbu_pipe_t pipe, hb_char_t *parent);
|
||||
|
||||
#include "./streamoptions.c"
|
||||
#include "./content.c"
|
||||
|
||||
void hbs_tag(hbs_options_t so, hbu_pipe_t pipe) {
|
||||
// $parent could be NULL
|
||||
void hbs_tag(hbs_options_t so, hbu_pipe_t pipe, hb_char_t *parent) {
|
||||
int self_closing = 0;
|
||||
|
||||
hbu_pipe_require(pipe, '<');
|
||||
|
@ -50,6 +55,13 @@ void hbs_tag(hbs_options_t so, hbu_pipe_t pipe) {
|
|||
hb_char_t *tag_name = hbu_buffer_underlying(opening_name);
|
||||
|
||||
// Non-standard tag checking is done in hbsh_tagname
|
||||
if (parent != NULL && (
|
||||
!hbr_whitelistparents_allowed(tag_name, parent) ||
|
||||
!hbr_whitelistchildren_allowed(parent, tag_name) ||
|
||||
!hbr_blacklistparents_allowed(tag_name, parent) ||
|
||||
!hbr_blacklistchildren_allowed(parent, tag_name))) {
|
||||
hbu_pipe_error(pipe, HBE_PARSE_ILLEGAL_CHILD, "Tag can't be a child there");
|
||||
}
|
||||
|
||||
// Self-closing or void tag
|
||||
if (self_closing || hbr_voidtags_check(tag_name)) {
|
||||
|
|
Loading…
Reference in New Issue