MCPcopy Create free account
hub / github.com/dillo-browser/dillo / Html_parse_entity

Function Html_parse_entity

src/html.cc:1035–1064  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

1033 * For valid entities, *entsize is set to the length of the parsed entity.
1034 */
1035static 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

Callers 2

a_Html_parse_entitiesFunction · 0.85
Html_get_attr2Function · 0.85

Calls 4

dStrndupFunction · 0.85
Html_parse_named_charrefFunction · 0.85
dFreeFunction · 0.85

Tested by

no test coverage detected