summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRupinder Singh Khokhar <rsk1coder99@gmail.com>2014-07-08 21:20:28 (GMT)
committer Rupinder Singh Khokhar <rsk1coder99@gmail.com>2014-08-01 16:14:32 (GMT)
commitab7c03d1289a774f89d682183f0c6462effcf7aa (patch)
tree281edffb8730f3fa33c107fc4149b465aa0e37cb
parentf2b1200a40f6d7f79ae2702119598bbc304edbd4 (diff)
downloadlibhubbub-ab7c03d1289a774f89d682183f0c6462effcf7aa.tar.gz
libhubbub-ab7c03d1289a774f89d682183f0c6462effcf7aa.tar.bz2
fixed handlers of table related and select related elements
-rw-r--r--src/treebuilder/in_body.c6
-rw-r--r--src/treebuilder/in_select.c4
-rw-r--r--src/treebuilder/in_table.c49
-rw-r--r--src/treebuilder/internal.h4
-rw-r--r--src/treebuilder/treebuilder.c43
-rw-r--r--test/data/tree-construction/INDEX2
6 files changed, 91 insertions, 17 deletions
diff --git a/src/treebuilder/in_body.c b/src/treebuilder/in_body.c
index 43fc678..eb82db0 100644
--- a/src/treebuilder/in_body.c
+++ b/src/treebuilder/in_body.c
@@ -385,15 +385,15 @@ hubbub_error process_start_tag(hubbub_treebuilder *treebuilder,
if (err != HUBBUB_OK)
return err;
- if (treebuilder->context.mode == IN_BODY) {
- treebuilder->context.mode = IN_SELECT;
- } else if (treebuilder->context.mode == IN_TABLE ||
+ if (treebuilder->context.mode == IN_TABLE ||
treebuilder->context.mode == IN_CAPTION ||
treebuilder->context.mode == IN_COLUMN_GROUP ||
treebuilder->context.mode == IN_TABLE_BODY ||
treebuilder->context.mode == IN_ROW ||
treebuilder->context.mode == IN_CELL) {
treebuilder->context.mode = IN_SELECT_IN_TABLE;
+ } else {
+ treebuilder->context.mode = IN_SELECT;
}
} else if (type == OPTGROUP || type == OPTION) {
err = process_opt_in_body(treebuilder, token);
diff --git a/src/treebuilder/in_select.c b/src/treebuilder/in_select.c
index a49b568..7c15b49 100644
--- a/src/treebuilder/in_select.c
+++ b/src/treebuilder/in_select.c
@@ -83,10 +83,10 @@ hubbub_error handle_in_select(hubbub_treebuilder *treebuilder,
err = insert_element(treebuilder, &token->data.tag,
true);
- } else if (type == SELECT || type == INPUT ||
+ } else if (type == SELECT || type == KEYGEN || type == INPUT ||
type == TEXTAREA) {
- if (element_in_scope(treebuilder, SELECT, TABLE_SCOPE)) {
+ if (element_in_scope(treebuilder, SELECT, SELECT_SCOPE)) {
element_stack_pop_until(treebuilder,
SELECT);
reset_insertion_mode(treebuilder);
diff --git a/src/treebuilder/in_table.c b/src/treebuilder/in_table.c
index d3d32e8..875e8ae 100644
--- a/src/treebuilder/in_table.c
+++ b/src/treebuilder/in_table.c
@@ -80,16 +80,19 @@ hubbub_error handle_in_table(hubbub_treebuilder *treebuilder,
{
hubbub_error err = HUBBUB_OK;
bool handled = true;
+ element_type type =
+ current_node(treebuilder);
+ bool tainted = !(type == TABLE ||
+ type == TBODY || type == TFOOT ||
+ type == THEAD || type == TR);
switch (token->type) {
case HUBBUB_TOKEN_CHARACTER:
- if (treebuilder->context.element_stack[
- current_table(treebuilder)
- ].tainted) {
+ if (tainted) {
handled = false;
} else {
- err = process_characters_expect_whitespace(
- treebuilder, token, true);
+ err = process_in_table_text(
+ treebuilder, token);
handled = (err == HUBBUB_OK);
}
break;
@@ -105,9 +108,6 @@ hubbub_error handle_in_table(hubbub_treebuilder *treebuilder,
{
element_type type = element_type_from_name(treebuilder,
&token->data.tag.name);
- bool tainted = treebuilder->context.element_stack[
- current_table(treebuilder)
- ].tainted;
if (type == CAPTION) {
clear_stack_table_context(treebuilder);
@@ -206,11 +206,40 @@ hubbub_error handle_in_table(hubbub_treebuilder *treebuilder,
reset_insertion_mode(treebuilder);
err = HUBBUB_REPROCESS;
- } else if (!tainted && (type == STYLE || type == SCRIPT)) {
+ } else if (type == STYLE || type == SCRIPT) {
err = handle_in_head(treebuilder, token);
- } else if (!tainted && type == INPUT) {
+ } else if (type == INPUT) {
err = process_input_in_table(treebuilder, token);
handled = (err == HUBBUB_OK);
+ } else if(type == FORM) {
+ element_context *stack = treebuilder->context.element_stack;
+ bool template_in_stack = false;
+ uint32_t n;
+ for (n = treebuilder->context.current_node;
+ n > 0; n--) {
+ if(stack[n].type == TEMPLATE) {
+ template_in_stack = true;
+ break;
+ }
+ }
+ if(template_in_stack == true ||
+ treebuilder->context.form_element != NULL ) {
+ /* ignore the token*/
+ break;
+ }
+ insert_element(treebuilder, &token->data.tag, true);
+ treebuilder->context.form_element =
+ treebuilder->context.element_stack[
+ treebuilder->context.current_node].node;
+ {
+ /* pop and unref */
+ hubbub_ns ns;
+ element_type otype;
+ void *node;
+
+ err = element_stack_pop(treebuilder, &ns,
+ &otype, &node);
+ }
} else {
handled = false;
}
diff --git a/src/treebuilder/internal.h b/src/treebuilder/internal.h
index 5eca574..941f94a 100644
--- a/src/treebuilder/internal.h
+++ b/src/treebuilder/internal.h
@@ -27,7 +27,7 @@ typedef enum
A, B, BIG, CODE, EM, FONT, I, NOBR, S, SMALL, STRIKE, STRONG, TT, U,
/* Phrasing */
/**< \todo Enumerate phrasing elements */
- COMMAND, DATAGRID, DIALOG, IMAGE,LABEL, OPTGROUP, OPTION, OUTPUT, RP, RT, RUBY, SPACER, SPAN, SUB, SUP, VAR,
+ COMMAND, DATAGRID, DIALOG, IMAGE, KEYGEN, LABEL, OPTGROUP, OPTION, OUTPUT, RP, RT, RUBY, SPACER, SPAN, SUB, SUP, VAR,
/* MathML */
MATH, MGLYPH, MALIGNMARK, MI, MO, MN, MS, MTEXT, ANNOTATION_XML,
/* SVG */
@@ -137,6 +137,8 @@ hubbub_error hubbub_treebuilder_token_handler(
hubbub_error process_characters_expect_whitespace(
hubbub_treebuilder *treebuilder, const hubbub_token *token,
bool insert_into_current_node);
+hubbub_error process_in_table_text(
+ hubbub_treebuilder *treebuilder, const hubbub_token *token);
hubbub_error process_comment_append(hubbub_treebuilder *treebuilder,
const hubbub_token *token, void *parent);
hubbub_error parse_generic_rcdata(hubbub_treebuilder *treebuilder,
diff --git a/src/treebuilder/treebuilder.c b/src/treebuilder/treebuilder.c
index a1bc802..11ff2a2 100644
--- a/src/treebuilder/treebuilder.c
+++ b/src/treebuilder/treebuilder.c
@@ -48,6 +48,7 @@ static const struct {
{ S("hr"), HR }, { S("iframe"), IFRAME },
{ S("image"), IMAGE }, { S("img"), IMG },
{ S("input"), INPUT }, { S("isindex"), ISINDEX },
+ { S("keygen"), KEYGEN },
{ S("li"), LI }, { S("link"), LINK },
{ S("listing"), LISTING }, { S("main"), MAIN },
{ S("menu"), MENU }, { S("menuitem"), MENUITEM },
@@ -425,6 +426,48 @@ hubbub_error process_characters_expect_whitespace(
}
/**
+ * Process a character token in table text
+ *
+ * \param treebuilder The treebuilder instance
+ * \param token The character token
+ * \return HUBBUB_REPROCESS if the token needs reprocessing
+ * HUBBUB_OK if it contained only whitespace,
+ * appropriate error otherwise
+ */
+hubbub_error process_in_table_text(
+ hubbub_treebuilder *treebuilder,
+ const hubbub_token *token)
+{
+ const uint8_t *data = token->data.character.ptr;
+ size_t len = token->data.character.len;
+ size_t c;
+
+ for (c = 0; c < len; c++) {
+ if (data[c] != 0x09 && data[c] != 0x0A &&
+ data[c] != 0x0C && data[c] != 0x20)
+ break;
+ }
+
+ if (c == len) {
+ hubbub_error error;
+ hubbub_string temp;
+
+ temp.ptr = data;
+ temp.len = c;
+
+ error = append_text(treebuilder, &temp);
+ if (error != HUBBUB_OK)
+ return error;
+ }
+
+ /* Non-whitespace characters in token, so reprocess */
+ if (c != len) {
+ return HUBBUB_REPROCESS;
+ }
+
+ return HUBBUB_OK;
+}
+/**
* Process a comment token, appending it to the given parent
*
* \param treebuilder The treebuilder instance
diff --git a/test/data/tree-construction/INDEX b/test/data/tree-construction/INDEX
index d45e4dd..f86396f 100644
--- a/test/data/tree-construction/INDEX
+++ b/test/data/tree-construction/INDEX
@@ -49,7 +49,7 @@ tests3.dat html5lib treebuilder tests
tests4.dat html5lib treebuilder tests
tests5.dat html5lib treebuilder tests
tests6.dat html5lib treebuilder tests
-#tests7.dat NA
+tests7.dat html5lib treebuilder tests
#tests8.dat NA
#tests9.dat NA
#tests_innerHTML_1.dat NA