* Given an entity, return the corresponding string. * Returns NULL if not a valid entity. * * The first character *token is assumed to be == '&' * * For valid entities, *entsize is set to the length of the parsed entity. */
| 1033 | * For valid entities, *entsize is set to the length of the parsed entity. |
| 1034 | */ |
| 1035 | static const char *Html_parse_entity(DilloHtml *html, const char *token, |
| 1036 | int toksize, int *entsize, bool_t is_attr) |
| 1037 | { |
| 1038 | const char *ret = NULL; |
| 1039 | char *tok; |
| 1040 | |
| 1041 | if (toksize > 50) { |
| 1042 | /* In pathological cases, attributes can be megabytes long and filled |
| 1043 | * with character references. As of HTML5, the longest defined character |
| 1044 | * reference is about 32 bytes long. |
| 1045 | */ |
| 1046 | toksize = 50; |
| 1047 | } |
| 1048 | |
| 1049 | token++; |
| 1050 | tok = dStrndup(token, (uint_t)toksize); |
| 1051 | |
| 1052 | if (*tok == '#') { |
| 1053 | ret = Html_parse_numeric_charref(html, tok+1, is_attr, entsize); |
| 1054 | } else if (isalpha(*tok)) { |
| 1055 | ret = Html_parse_named_charref(html, tok, is_attr, entsize); |
| 1056 | } else if (prefs.show_extra_warnings && |
| 1057 | (!(html->DocType == DT_HTML && html->DocTypeVersion >= 5.0f))) { |
| 1058 | // HTML5 doesn't mind literal '&'s. |
| 1059 | BUG_MSG("Literal '&'."); |
| 1060 | } |
| 1061 | dFree(tok); |
| 1062 | |
| 1063 | return ret; |
| 1064 | } |
| 1065 | |
| 1066 | /** |
| 1067 | * Parse all the entities in a token. Takes the token and its length, and |
no test coverage detected