/* attrs.c -- recognize HTML attributes
(c) 1998-2009 (W3C) MIT, ERCIM, Keio University
See tidy.h for the copyright notice.
*/
#include "tidy-int.h"
#include "attrs.h"
#include "message.h"
#include "tmbstr.h"
#include "utf8.h"
/*
Bind attribute types to procedures to check values.
You can add new procedures for better validation
and each procedure has access to the node in which
the attribute occurred as well as the attribute name
and its value.
By default, attributes are checked without regard
to the element they are found on. You have the choice
of making the procedure test which element is involved
or in writing methods for each element which controls
exactly how the attributes of that element are checked.
This latter approach is best for detecting the absence
of required attributes.
*/
static AttrCheck CheckAction;
static AttrCheck CheckScript;
static AttrCheck CheckName;
static AttrCheck CheckId;
static AttrCheck CheckAlign;
static AttrCheck CheckValign;
static AttrCheck CheckBool;
static AttrCheck CheckLength;
static AttrCheck CheckTarget;
static AttrCheck CheckFsubmit;
static AttrCheck CheckClear;
static AttrCheck CheckShape;
static AttrCheck CheckNumber;
static AttrCheck CheckScope;
static AttrCheck CheckColor;
static AttrCheck CheckVType;
static AttrCheck CheckScroll;
static AttrCheck CheckTextDir;
static AttrCheck CheckLang;
static AttrCheck CheckType;
#define CH_PCDATA NULL
#define CH_CHARSET NULL
#define CH_TYPE CheckType
#define CH_XTYPE NULL
#define CH_CHARACTER NULL
#define CH_URLS NULL
#define CH_URL TY_(CheckUrl)
#define CH_SCRIPT CheckScript
#define CH_ALIGN CheckAlign
#define CH_VALIGN CheckValign
#define CH_COLOR CheckColor
#define CH_CLEAR CheckClear
#define CH_BORDER CheckBool /* kludge */
#define CH_LANG CheckLang
#define CH_BOOL CheckBool
#define CH_COLS NULL
#define CH_NUMBER CheckNumber
#define CH_LENGTH CheckLength
#define CH_COORDS NULL
#define CH_DATE NULL
#define CH_TEXTDIR CheckTextDir
#define CH_IDREFS NULL
#define CH_IDREF NULL
#define CH_IDDEF CheckId
#define CH_NAME CheckName
#define CH_TFRAME NULL
#define CH_FBORDER NULL
#define CH_MEDIA NULL
#define CH_FSUBMIT CheckFsubmit
#define CH_LINKTYPES NULL
#define CH_TRULES NULL
#define CH_SCOPE CheckScope
#define CH_SHAPE CheckShape
#define CH_SCROLL CheckScroll
#define CH_TARGET CheckTarget
#define CH_VTYPE CheckVType
#define CH_ACTION CheckAction
static const Attribute attribute_defs [] =
{
{ TidyAttr_UNKNOWN, "unknown!", NULL },
{ TidyAttr_ABBR, "abbr", CH_PCDATA },
{ TidyAttr_ACCEPT, "accept", CH_XTYPE },
{ TidyAttr_ACCEPT_CHARSET, "accept-charset", CH_CHARSET },
{ TidyAttr_ACCESSKEY, "accesskey", CH_CHARACTER },
{ TidyAttr_ACTION, "action", CH_ACTION },
{ TidyAttr_ADD_DATE, "add_date", CH_PCDATA }, /* A */
{ TidyAttr_ALIGN, "align", CH_ALIGN }, /* varies by element */
{ TidyAttr_ALINK, "alink", CH_COLOR },
{ TidyAttr_ALT, "alt", CH_PCDATA }, /* nowrap */
{ TidyAttr_ARCHIVE, "archive", CH_URLS }, /* space or comma separated list */
{ TidyAttr_AXIS, "axis", CH_PCDATA },
{ TidyAttr_BACKGROUND, "background", CH_URL },
{ TidyAttr_BGCOLOR, "bgcolor", CH_COLOR },
{ TidyAttr_BGPROPERTIES, "bgproperties", CH_PCDATA }, /* BODY "fixed" fixes background */
{ TidyAttr_BORDER, "border", CH_BORDER }, /* like LENGTH + "border" */
{ TidyAttr_BORDERCOLOR, "bordercolor", CH_COLOR }, /* used on TABLE */
{ TidyAttr_BOTTOMMARGIN, "bottommargin", CH_NUMBER }, /* used on BODY */
{ TidyAttr_CELLPADDING, "cellpadding", CH_LENGTH }, /* % or pixel values */
{ TidyAttr_CELLSPACING, "cellspacing", CH_LENGTH },
{ TidyAttr_CHAR, "char", CH_CHARACTER },
{ TidyAttr_CHAROFF, "charoff", CH_LENGTH },
{ TidyAttr_CHARSET, "charset", CH_CHARSET },
{ TidyAttr_CHECKED, "checked", CH_BOOL }, /* i.e. "checked" or absent */
{ TidyAttr_CITE, "cite", CH_URL },
{ TidyAttr_CLASS, "class", CH_PCDATA },
{ TidyAttr_CLASSID, "classid", CH_URL },
{ TidyAttr_CLEAR, "clear", CH_CLEAR }, /* BR: left, right, all */
{ TidyAttr_CODE, "code", CH_PCDATA }, /* APPLET */
{ TidyAttr_CODEBASE, "codebase", CH_URL }, /* OBJECT */
{ TidyAttr_CODETYPE, "codetype", CH_XTYPE }, /* OBJECT */
{ TidyAttr_COLOR, "color", CH_COLOR }, /* BASEFONT, FONT */
{ TidyAttr_COLS, "cols", CH_COLS }, /* TABLE & FRAMESET */
{ TidyAttr_COLSPAN, "colspan", CH_NUMBER },
{ TidyAttr_COMPACT, "compact", CH_BOOL }, /* lists */
{ TidyAttr_CONTENT, "content", CH_PCDATA },
{ TidyAttr_COORDS, "coords", CH_COORDS }, /* AREA, A */
{ TidyAttr_DATA, "data", CH_URL }, /* OBJECT */
{ TidyAttr_DATAFLD, "datafld", CH_PCDATA }, /* used on DIV, IMG */
{ TidyAttr_DATAFORMATAS, "dataformatas", CH_PCDATA }, /* used on DIV, IMG */
{ TidyAttr_DATAPAGESIZE, "datapagesize", CH_NUMBER }, /* used on DIV, IMG */
{ TidyAttr_DATASRC, "datasrc", CH_URL }, /* used on TABLE */
{ TidyAttr_DATETIME, "datetime", CH_DATE }, /* INS, DEL */
{ TidyAttr_DECLARE, "declare", CH_BOOL }, /* OBJECT */
{ TidyAttr_DEFER, "defer", CH_BOOL }, /* SCRIPT */
{ TidyAttr_DIR, "dir", CH_TEXTDIR }, /* ltr or rtl */
{ TidyAttr_DISABLED, "disabled", CH_BOOL }, /* form fields */
{ TidyAttr_ENCODING, "encoding", CH_PCDATA }, /* */
{ TidyAttr_ENCTYPE, "enctype", CH_XTYPE }, /* FORM */
{ TidyAttr_FACE, "face", CH_PCDATA }, /* BASEFONT, FONT */
{ TidyAttr_FOR, "for", CH_IDREF }, /* LABEL */
{ TidyAttr_FRAME, "frame", CH_TFRAME }, /* TABLE */
{ TidyAttr_FRAMEBORDER, "frameborder", CH_FBORDER }, /* 0 or 1 */
{ TidyAttr_FRAMESPACING, "framespacing", CH_NUMBER },
{ TidyAttr_GRIDX, "gridx", CH_NUMBER }, /* TABLE Adobe golive*/
{ TidyAttr_GRIDY, "gridy", CH_NUMBER }, /* TABLE Adobe golive */
{ TidyAttr_HEADERS, "headers", CH_IDREFS }, /* table cells */
{ TidyAttr_HEIGHT, "height", CH_LENGTH }, /* pixels only for TH/TD */
{ TidyAttr_HREF, "href", CH_URL }, /* A, AREA, LINK and BASE */
{ TidyAttr_HREFLANG, "hreflang", CH_LANG }, /* A, LINK */
{ TidyAttr_HSPACE, "hspace", CH_NUMBER }, /* APPLET, IMG, OBJECT */
{ TidyAttr_HTTP_EQUIV, "http-equiv", CH_PCDATA }, /* META */
{ TidyAttr_ID, "id", CH_IDDEF },
{ TidyAttr_ISMAP, "ismap", CH_BOOL }, /* IMG */
{ TidyAttr_ITEMID, "itemid", CH_PCDATA },
{ TidyAttr_ITEMPROP, "itemprop", CH_PCDATA },
{ TidyAttr_ITEMREF, "itemref", CH_PCDATA },
{ TidyAttr_ITEMSCOPE, "itemscope", CH_BOOL },
{ TidyAttr_ITEMTYPE, "itemtype", CH_URL },
{ TidyAttr_LABEL, "label", CH_PCDATA }, /* OPT, OPTGROUP */
{ TidyAttr_LANG, "lang", CH_LANG },
{ TidyAttr_LANGUAGE, "language", CH_PCDATA }, /* SCRIPT */
{ TidyAttr_LAST_MODIFIED, "last_modified", CH_PCDATA }, /* A */
{ TidyAttr_LAST_VISIT, "last_visit", CH_PCDATA }, /* A */
{ TidyAttr_LEFTMARGIN, "leftmargin", CH_NUMBER }, /* used on BODY */
{ TidyAttr_LINK, "link", CH_COLOR }, /* BODY */
{ TidyAttr_LONGDESC, "longdesc", CH_URL }, /* IMG */
{ TidyAttr_LOWSRC, "lowsrc", CH_URL }, /* IMG */
{ TidyAttr_MARGINHEIGHT, "marginheight", CH_NUMBER }, /* FRAME, IFRAME, BODY */
{ TidyAttr_MARGINWIDTH, "marginwidth", CH_NUMBER }, /* ditto */
{ TidyAttr_MAXLENGTH, "maxlength", CH_NUMBER }, /* INPUT */
{ TidyAttr_MEDIA, "media", CH_MEDIA }, /* STYLE, LINK */
{ TidyAttr_METHOD, "method", CH_FSUBMIT }, /* FORM: get or post */
{ TidyAttr_MULTIPLE, "multiple", CH_BOOL }, /* SELECT */
{ TidyAttr_NAME, "name", CH_NAME },
{ TidyAttr_NOHREF, "nohref", CH_BOOL }, /* AREA */
{ TidyAttr_NORESIZE, "noresize", CH_BOOL }, /* FRAME */
{ TidyAttr_NOSHADE, "noshade", CH_BOOL }, /* HR */
{ TidyAttr_NOWRAP, "nowrap", CH_BOOL }, /* table cells */
{ TidyAttr_OBJECT, "object", CH_PCDATA }, /* APPLET */
{ TidyAttr_OnAFTERUPDATE, "onafterupdate", CH_SCRIPT },
{ TidyAttr_OnBEFOREUNLOAD, "onbeforeunload", CH_SCRIPT },
{ TidyAttr_OnBEFOREUPDATE, "onbeforeupdate", CH_SCRIPT },
{ TidyAttr_OnBLUR, "onblur", CH_SCRIPT }, /* event */
{ TidyAttr_OnCHANGE, "onchange", CH_SCRIPT }, /* event */
{ TidyAttr_OnCLICK, "onclick", CH_SCRIPT }, /* event */
{ TidyAttr_OnDATAAVAILABLE, "ondataavailable", CH_SCRIPT }, /* object, applet */
{ TidyAttr_OnDATASETCHANGED, "ondatasetchanged", CH_SCRIPT }, /* object, applet */
{ TidyAttr_OnDATASETCOMPLETE, "ondatasetcomplete", CH_SCRIPT },
{ TidyAttr_OnDBLCLICK, "ondblclick", CH_SCRIPT }, /* event */
{ TidyAttr_OnERRORUPDATE, "onerrorupdate", CH_SCRIPT }, /* form fields */
{ TidyAttr_OnFOCUS, "onfocus", CH_SCRIPT }, /* event */
{ TidyAttr_OnKEYDOWN, "onkeydown", CH_SCRIPT }, /* event */
{ TidyAttr_OnKEYPRESS, "onkeypress", CH_SCRIPT }, /* event */
{ TidyAttr_OnKEYUP, "onkeyup", CH_SCRIPT }, /* event */
{ TidyAttr_OnLOAD, "onload", CH_SCRIPT }, /* event */
{ TidyAttr_OnMOUSEDOWN, "onmousedown", CH_SCRIPT }, /* event */
{ TidyAttr_OnMOUSEMOVE, "onmousemove", CH_SCRIPT }, /* event */
{ TidyAttr_OnMOUSEOUT, "onmouseout", CH_SCRIPT }, /* event */
{ TidyAttr_OnMOUSEOVER, "onmouseover", CH_SCRIPT }, /* event */
{ TidyAttr_OnMOUSEUP, "onmouseup", CH_SCRIPT }, /* event */
{ TidyAttr_OnRESET, "onreset", CH_SCRIPT }, /* event */
{ TidyAttr_OnROWENTER, "onrowenter", CH_SCRIPT }, /* form fields */
{ TidyAttr_OnROWEXIT, "onrowexit", CH_SCRIPT }, /* form fields */
{ TidyAttr_OnSELECT, "onselect", CH_SCRIPT }, /* event */
{ TidyAttr_OnSUBMIT, "onsubmit", CH_SCRIPT }, /* event */
{ TidyAttr_OnUNLOAD, "onunload", CH_SCRIPT }, /* event */
{ TidyAttr_PROFILE, "profile", CH_URL }, /* HEAD */
{ TidyAttr_PROMPT, "prompt", CH_PCDATA }, /* ISINDEX */
{ TidyAttr_RBSPAN, "rbspan", CH_NUMBER }, /* ruby markup */
{ TidyAttr_READONLY, "readonly", CH_BOOL }, /* form fields */
{ TidyAttr_REL, "rel", CH_LINKTYPES },
{ TidyAttr_REV, "rev", CH_LINKTYPES },
{ TidyAttr_RIGHTMARGIN, "rightmargin", CH_NUMBER }, /* used on BODY */
{ TidyAttr_ROLE, "role", CH_PCDATA },
{ TidyAttr_ROWS, "rows", CH_NUMBER }, /* TEXTAREA */
{ TidyAttr_ROWSPAN, "rowspan", CH_NUMBER }, /* table cells */
{ TidyAttr_RULES, "rules", CH_TRULES }, /* TABLE */
{ TidyAttr_SCHEME, "scheme", CH_PCDATA }, /* META */
{ TidyAttr_SCOPE, "scope", CH_SCOPE }, /* table cells */
{ TidyAttr_SCROLLING, "scrolling", CH_SCROLL }, /* yes, no or auto */
{ TidyAttr_SELECTED, "selected", CH_BOOL }, /* OPTION */
{ TidyAttr_SHAPE, "shape", CH_SHAPE }, /* AREA, A */
{ TidyAttr_SHOWGRID, "showgrid", CH_BOOL }, /* TABLE Adobe golive */
{ TidyAttr_SHOWGRIDX, "showgridx", CH_BOOL }, /* TABLE Adobe golive*/
{ TidyAttr_SHOWGRIDY, "showgridy", CH_BOOL }, /* TABLE Adobe golive*/
{ TidyAttr_SIZE, "size", CH_NUMBER }, /* HR, FONT, BASEFONT, SELECT */
{ TidyAttr_SPAN, "span", CH_NUMBER }, /* COL, COLGROUP */
{ TidyAttr_SRC, "src", CH_URL }, /* IMG, FRAME, IFRAME */
{ TidyAttr_STANDBY, "standby", CH_PCDATA }, /* OBJECT */
{ TidyAttr_START, "start", CH_NUMBER }, /* OL */
{ TidyAttr_STYLE, "style", CH_PCDATA },
{ TidyAttr_SUMMARY, "summary", CH_PCDATA }, /* TABLE */
{ TidyAttr_TABINDEX, "tabindex", CH_NUMBER }, /* fields, OBJECT and A */
{ TidyAttr_TARGET, "target", CH_TARGET }, /* names a frame/window */
{ TidyAttr_TEXT, "text", CH_COLOR }, /* BODY */
{ TidyAttr_TITLE, "title", CH_PCDATA }, /* text tool tip */
{ TidyAttr_TOPMARGIN, "topmargin", CH_NUMBER }, /* used on BODY */
{ TidyAttr_TYPE, "type", CH_TYPE }, /* also used by SPACER */
{ TidyAttr_USEMAP, "usemap", CH_URL }, /* things with images */
{ TidyAttr_VALIGN, "valign", CH_VALIGN },
{ TidyAttr_VALUE, "value", CH_PCDATA },
{ TidyAttr_VALUETYPE, "valuetype", CH_VTYPE }, /* PARAM: data, ref, object */
{ TidyAttr_VERSION, "version", CH_PCDATA }, /* HTML */
{ TidyAttr_VLINK, "vlink", CH_COLOR }, /* BODY */
{ TidyAttr_VSPACE, "vspace", CH_NUMBER }, /* IMG, OBJECT, APPLET */
{ TidyAttr_WIDTH, "width", CH_LENGTH }, /* pixels only for TD/TH */
{ TidyAttr_WRAP, "wrap", CH_PCDATA }, /* textarea */
{ TidyAttr_XML_LANG, "xml:lang", CH_LANG }, /* XML language */
{ TidyAttr_XML_SPACE, "xml:space", CH_PCDATA }, /* XML white space */
/* todo: VERS_ALL is wrong! */
{ TidyAttr_XMLNS, "xmlns", CH_PCDATA }, /* name space */
{ TidyAttr_EVENT, "event", CH_PCDATA }, /* reserved for