Monday, 31 March 2014

[PATCH 04/10] comment end bang state added

---
src/tokeniser/tokeniser.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/tokeniser/tokeniser.c b/src/tokeniser/tokeniser.c
index 7d783e6..5bb59a8 100644
--- a/src/tokeniser/tokeniser.c
+++ b/src/tokeniser/tokeniser.c
@@ -72,6 +72,7 @@ typedef enum hubbub_tokeniser_state {
STATE_COMMENT,
STATE_COMMENT_END_DASH,
STATE_COMMENT_END,
+ STATE_COMMENT_END_BANG,
STATE_MATCH_DOCTYPE,
STATE_DOCTYPE,
STATE_BEFORE_DOCTYPE_NAME,
@@ -535,6 +536,7 @@ hubbub_error hubbub_tokeniser_run(hubbub_tokeniser *tokeniser)
case STATE_COMMENT:
case STATE_COMMENT_END_DASH:
case STATE_COMMENT_END:
+ case STATE_COMMENT_END_BANG:
cont = hubbub_tokeniser_handle_comment(tokeniser);
break;
state(STATE_MATCH_DOCTYPE)
@@ -1888,7 +1890,8 @@ hubbub_error hubbub_tokeniser_handle_comment(hubbub_tokeniser *tokeniser)

if (c == '>' && (tokeniser->state == STATE_COMMENT_START_DASH ||
tokeniser->state == STATE_COMMENT_START ||
- tokeniser->state == STATE_COMMENT_END)) {
+ tokeniser->state == STATE_COMMENT_END ||
+ tokeniser->state == STATE_COMMENT_END_BANG)) {
tokeniser->context.pending += len;

/** \todo parse error if state != COMMENT_END */
@@ -1910,9 +1913,21 @@ hubbub_error hubbub_tokeniser_handle_comment(hubbub_tokeniser *tokeniser)
return hubbub_error_from_parserutils_error(
error);
}
+ }else if(tokeniser->state == STATE_COMMENT_END_BANG) {
+ error = parserutils_buffer_append(tokeniser->buffer,
+ (uint8_t *) "--!", SLEN("--!"));
+ if (error != PARSERUTILS_OK) {
+ return hubbub_error_from_parserutils_error(
+ error);
+ }
+ tokeniser->state = STATE_COMMENT_END_DASH;
}

tokeniser->context.pending += len;
+ } else if (c == '!' && tokeniser->state == STATE_COMMENT_END) {
+ tokeniser->state = STATE_COMMENT_END_BANG;
+ tokeniser->context.pending += len;
+ return HUBBUB_OK;
} else {
if (tokeniser->state == STATE_COMMENT_START_DASH ||
tokeniser->state == STATE_COMMENT_END_DASH) {
@@ -1929,6 +1944,13 @@ hubbub_error hubbub_tokeniser_handle_comment(hubbub_tokeniser *tokeniser)
return hubbub_error_from_parserutils_error(
error);
}
+ } else if (tokeniser->state == STATE_COMMENT_END_BANG) {
+ error = parserutils_buffer_append(tokeniser->buffer,
+ (uint8_t *) "--!", SLEN("--!"));
+ if (error != PARSERUTILS_OK) {
+ return hubbub_error_from_parserutils_error(
+ error);
+ }
}

if (c == '\0') {
--
1.8.3.2

No comments:

Post a Comment