mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Fix SGML parsing and scanning so that all tests succeeds
This includes checking the return token of get_next_dom_scanner_token() and fixing the calculated size of recovered processing instruction data tokens.
This commit is contained in:
parent
0160c0a464
commit
f75ccffbc7
@ -186,15 +186,23 @@ parse_sgml_attributes(struct dom_stack *stack, struct dom_scanner *scanner)
|
||||
|
||||
/* Skip the attribute name token */
|
||||
token = get_next_dom_scanner_token(scanner);
|
||||
|
||||
if (token && token->type == '=') {
|
||||
/* If the token is not a valid value token
|
||||
* ignore it. */
|
||||
token = get_next_dom_scanner_token(scanner);
|
||||
if (token && token->type == SGML_TOKEN_INCOMPLETE)
|
||||
return SGML_PARSER_CODE_INCOMPLETE;
|
||||
|
||||
if (token
|
||||
&& token->type != SGML_TOKEN_IDENT
|
||||
&& token->type != SGML_TOKEN_ATTRIBUTE
|
||||
&& token->type != SGML_TOKEN_STRING)
|
||||
token = NULL;
|
||||
|
||||
} else if (token && token->type == SGML_TOKEN_INCOMPLETE) {
|
||||
return SGML_PARSER_CODE_INCOMPLETE;
|
||||
|
||||
} else {
|
||||
token = NULL;
|
||||
}
|
||||
@ -303,7 +311,8 @@ parse_sgml_plain(struct dom_stack *stack, struct dom_scanner *scanner)
|
||||
|
||||
/* Skip the target token */
|
||||
token = get_next_dom_scanner_token(scanner);
|
||||
if (!token) break;
|
||||
if (!token || token->type == SGML_TOKEN_INCOMPLETE)
|
||||
return SGML_PARSER_CODE_INCOMPLETE;
|
||||
|
||||
assert(token->type == SGML_TOKEN_PROCESS_DATA);
|
||||
|
||||
|
@ -582,6 +582,8 @@ static inline void
|
||||
scan_sgml_proc_inst_token(struct dom_scanner *scanner, struct dom_scanner_token *token)
|
||||
{
|
||||
unsigned char *string = scanner->position;
|
||||
/* The length can be empty for '<??>'. */
|
||||
size_t length = -1;
|
||||
|
||||
token->string.string = string;
|
||||
|
||||
@ -591,21 +593,23 @@ scan_sgml_proc_inst_token(struct dom_scanner *scanner, struct dom_scanner_token
|
||||
for ( ; (string = skip_sgml_chars(scanner, string, '>')); string++) {
|
||||
if (string[-1] == '?') {
|
||||
string++;
|
||||
length = string - token->string.string - 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string) {
|
||||
/* Makes the next succeed when checking for incompletion. */
|
||||
string = scanner->end;
|
||||
|
||||
if (check_sgml_incomplete(scanner, string)) {
|
||||
set_sgml_incomplete(scanner, token);
|
||||
return;
|
||||
}
|
||||
|
||||
string = scanner->end;
|
||||
}
|
||||
|
||||
token->type = SGML_TOKEN_PROCESS_DATA;
|
||||
token->string.length = string - token->string.string - 2;
|
||||
token->string.length = length >= 0 ? length : string - token->string.string;
|
||||
token->precedence = get_sgml_precedence(token->type);
|
||||
scanner->position = string;
|
||||
scanner->state = SGML_STATE_TEXT;
|
||||
|
Loading…
x
Reference in New Issue
Block a user