Enforce UCASE_TAG

This commit is contained in:
Wilson Lin 2018-08-04 23:52:06 +12:00
parent 8d46291542
commit 89921f9397
2 changed files with 20 additions and 7 deletions

View File

@ -2,12 +2,15 @@
#define _HDR_HYPERBUILD_STREAM_HELPER_TAGNAME
#include "../../rule/char/tagname.c"
#include "../../rule/char/ucalpha.c"
#include "../../util/hbchar.h"
#include "../../util/buffer.c"
#include "../../util/pipe.c"
hbu_buffer_t hbsh_tagname(hbu_pipe_t pipe) {
#include "../streamoptions.c"
hbu_buffer_t hbsh_tagname(hbs_options_t so, hbu_pipe_t pipe) {
hbu_buffer_t name = hbu_buffer_create();
while (1) {
@ -17,11 +20,23 @@ hbu_buffer_t hbsh_tagname(hbu_pipe_t pipe) {
break;
}
hbu_buffer_append(name, c);
if (hbr_ucalpha_check(c)) {
if (!hbs_options_supressed_error(so, HBE_PARSE_UCASE_TAG)) {
hbu_pipe_error(pipe, HBE_PARSE_UCASE_TAG, "Uppercase character in tag");
}
// Lowercase to normalise when checking against rules and closing tag
hbu_buffer_append(name, c + 32);
} else {
hbu_buffer_append(name, c);
}
hbu_pipe_accept(pipe);
}
if (!hbs_options_supressed_error(so, HBE_PARSE_NONSTANDARD_TAG) && !hbr_tags_check(hbu_buffer_underlying(name))) {
hbu_pipe_error(pipe, HBE_PARSE_NONSTANDARD_TAG, "Non-standard tag");
}
return name;
}

View File

@ -24,7 +24,7 @@ void hbs_tag(hbs_options_t so, hbu_pipe_t pipe) {
int self_closing = 0;
hbu_pipe_require(pipe, '<');
hbu_buffer_t opening_name = hbsh_tagname(pipe);
hbu_buffer_t opening_name = hbsh_tagname(so, pipe);
while (1) {
hbu_pipe_accept_while_predicate(pipe, &hbr_whitespace_check);
@ -49,9 +49,7 @@ void hbs_tag(hbs_options_t so, hbu_pipe_t pipe) {
hb_char_t *tag_name = hbu_buffer_underlying(opening_name);
if (!hbs_options_supressed_error(so, HBE_PARSE_NONSTANDARD_TAG) && !hbr_tags_check(tag_name)) {
hbu_pipe_error(pipe, HBE_PARSE_NONSTANDARD_TAG, "Non-standard tag");
}
// Non-standard tag checking is done in hbsh_tagname
// Self-closing or void tag
if (self_closing || hbr_voidtags_check(tag_name)) {
@ -72,7 +70,7 @@ void hbs_tag(hbs_options_t so, hbu_pipe_t pipe) {
// Closing tag for non-void
hbu_pipe_require(pipe, '<');
hbu_pipe_require(pipe, '/');
hbu_buffer_t closing_name = hbsh_tagname(pipe);
hbu_buffer_t closing_name = hbsh_tagname(so, pipe);
hbu_pipe_require(pipe, '>');
if (!hbu_buffer_equal(opening_name, closing_name)) {