From 703a8b505cf698c310497086334408d44397d121 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 22 Jan 2009 00:45:26 +0000 Subject: Move isDigit() and isHex() to utils.h. Fix #rgb/#rrggbb parsing to ensure that the characters are valid hex digits. svn path=/trunk/libcss/; revision=6167 --- src/lex/lex.c | 12 ------------ src/parse/properties.c | 13 +++++++++++-- src/utils/utils.h | 10 ++++++++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/lex/lex.c b/src/lex/lex.c index 2b565d0..159be24 100644 --- a/src/lex/lex.c +++ b/src/lex/lex.c @@ -163,8 +163,6 @@ static inline bool startNMChar(uint8_t c); static inline bool startNMStart(uint8_t c); static inline bool startStringChar(uint8_t c); static inline bool startURLChar(uint8_t c); -static inline bool isDigit(uint8_t c); -static inline bool isHex(uint8_t c); static inline bool isSpace(uint8_t c); /** @@ -2133,16 +2131,6 @@ bool startURLChar(uint8_t c) ('*' <= c && c <= '~') || c >= 0x80 || c == '\\'; } -bool isDigit(uint8_t c) -{ - return '0' <= c && c <= '9'; -} - -bool isHex(uint8_t c) -{ - return isDigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); -} - bool isSpace(uint8_t c) { return c == ' ' || c == '\r' || c == '\n' || c == '\f' || c == '\t'; diff --git a/src/parse/properties.c b/src/parse/properties.c index ea2635d..a3c598a 100644 --- a/src/parse/properties.c +++ b/src/parse/properties.c @@ -6479,7 +6479,10 @@ css_error parse_colour_specifier(css_language *c, if (token->type == CSS_TOKEN_IDENT) { /** \todo Parse colour names */ } else if (token->type == CSS_TOKEN_HASH) { - if (token->idata->len == 3) { + if (token->idata->len == 3 && + isHex(token->idata->data[0]) && + isHex(token->idata->data[1]) && + isHex(token->idata->data[2])) { r = charToHex(token->idata->data[0]); g = charToHex(token->idata->data[1]); b = charToHex(token->idata->data[2]); @@ -6487,7 +6490,13 @@ css_error parse_colour_specifier(css_language *c, r |= (r << 4); g |= (g << 4); b |= (b << 4); - } else if (token->idata->len == 6) { + } else if (token->idata->len == 6 && + isHex(token->idata->data[0]) && + isHex(token->idata->data[1]) && + isHex(token->idata->data[2]) && + isHex(token->idata->data[3]) && + isHex(token->idata->data[4]) && + isHex(token->idata->data[5])) { r = (charToHex(token->idata->data[0]) << 4); r |= charToHex(token->idata->data[1]); g = (charToHex(token->idata->data[2]) << 4); diff --git a/src/utils/utils.h b/src/utils/utils.h index 835265b..8100669 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -125,6 +125,16 @@ static inline fixed number_from_css_string(const css_string *string, return FMULI(((intpart << 10) | fracpart), sign); } +static inline bool isDigit(uint8_t c) +{ + return '0' <= c && c <= '9'; +} + +static inline bool isHex(uint8_t c) +{ + return isDigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'); +} + static inline uint32_t charToHex(uint8_t c) { switch (c) { -- cgit v1.2.3