Address issue #472.

This commit is contained in:
Jim Derry 2017-03-08 10:29:41 -05:00
parent b047e32a18
commit 005127c733
2 changed files with 27 additions and 7 deletions

View file

@ -52,10 +52,18 @@ typedef enum
These TidyOptionId are used throughout libtidy, and also These TidyOptionId are used throughout libtidy, and also
have associated localized strings to describe them. have associated localized strings to describe them.
Ensure struct order is same order as config.c:option_defs structure!
*/ */
typedef enum typedef enum
{ {
TidyUnknownOption = 0, /**< Unknown option! */ TidyUnknownOption = 0, /**< Unknown option! */
#ifndef DOXYGEN_SHOULD_SKIP_THIS
TidyDoctypeMode, /**< Internal use ONLY */
TidyEmacsFile, /**< Internal use ONLY */
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
TidyIndentSpaces, /**< Indentation n spaces/tabs */ TidyIndentSpaces, /**< Indentation n spaces/tabs */
TidyWrapLen, /**< Wrap margin */ TidyWrapLen, /**< Wrap margin */
TidyTabSize, /**< Expand tabs to n spaces */ TidyTabSize, /**< Expand tabs to n spaces */
@ -65,7 +73,6 @@ typedef enum
TidyOutCharEncoding, /**< Output character encoding (if different) */ TidyOutCharEncoding, /**< Output character encoding (if different) */
TidyNewline, /**< Output line ending (default to platform) */ TidyNewline, /**< Output line ending (default to platform) */
TidyDoctypeMode, /**< See doctype property */
TidyDoctype, /**< User specified doctype */ TidyDoctype, /**< User specified doctype */
TidyDuplicateAttrs, /**< Keep first or last duplicate attribute */ TidyDuplicateAttrs, /**< Keep first or last duplicate attribute */
@ -122,7 +129,6 @@ typedef enum
TidyWord2000, /**< Draconian cleaning for Word2000 */ TidyWord2000, /**< Draconian cleaning for Word2000 */
TidyMark, /**< Add meta element indicating tidied doc */ TidyMark, /**< Add meta element indicating tidied doc */
TidyEmacs, /**< If true format error output for GNU Emacs */ TidyEmacs, /**< If true format error output for GNU Emacs */
TidyEmacsFile, /**< Name of current Emacs file */
TidyLiteralAttribs, /**< If true attributes may use newlines */ TidyLiteralAttribs, /**< If true attributes may use newlines */
TidyBodyOnly, /**< Output BODY content only */ TidyBodyOnly, /**< Output BODY content only */
TidyFixUri, /**< Applies URI encoding if necessary */ TidyFixUri, /**< Applies URI encoding if necessary */

View file

@ -212,9 +212,12 @@ static ParseProperty ParseRepeatAttr;
\*/ \*/
static ParseProperty ParseTabs; static ParseProperty ParseTabs;
/* Ensure struct order is same order as tidyenum.h:TidyOptionId! */
static const TidyOptionImpl option_defs[] = static const TidyOptionImpl option_defs[] =
{ {
{ TidyUnknownOption, MS, "unknown!", IN, 0, NULL, NULL }, { TidyUnknownOption, MS, "unknown!", IN, 0, NULL, NULL },
{ TidyDoctypeMode, MU, "doctype-mode", IN, TidyDoctypeAuto, NULL, doctypePicks },
{ TidyEmacsFile, MS, "gnu-emacs-file", ST, 0, ParseString, NULL },
{ TidyIndentSpaces, PP, "indent-spaces", IN, 2, ParseInt, NULL }, { TidyIndentSpaces, PP, "indent-spaces", IN, 2, ParseInt, NULL },
{ TidyWrapLen, PP, "wrap", IN, 68, ParseInt, NULL }, { TidyWrapLen, PP, "wrap", IN, 68, ParseInt, NULL },
{ TidyTabSize, PP, "tab-size", IN, 8, ParseInt, NULL }, { TidyTabSize, PP, "tab-size", IN, 8, ParseInt, NULL },
@ -222,7 +225,6 @@ static const TidyOptionImpl option_defs[] =
{ TidyInCharEncoding, CE, "input-encoding", IN, UTF8, ParseCharEnc, charEncPicks }, { TidyInCharEncoding, CE, "input-encoding", IN, UTF8, ParseCharEnc, charEncPicks },
{ TidyOutCharEncoding, CE, "output-encoding", IN, UTF8, ParseCharEnc, charEncPicks }, { TidyOutCharEncoding, CE, "output-encoding", IN, UTF8, ParseCharEnc, charEncPicks },
{ TidyNewline, CE, "newline", IN, DLF, ParseNewline, newlinePicks }, { TidyNewline, CE, "newline", IN, DLF, ParseNewline, newlinePicks },
{ TidyDoctypeMode, MU, "doctype-mode", IN, TidyDoctypeAuto, NULL, doctypePicks },
{ TidyDoctype, MU, "doctype", ST, 0, ParseDocType, doctypePicks }, { TidyDoctype, MU, "doctype", ST, 0, ParseDocType, doctypePicks },
{ TidyDuplicateAttrs, MU, "repeated-attributes", IN, TidyKeepLast, ParseRepeatAttr, repeatAttrPicks }, { TidyDuplicateAttrs, MU, "repeated-attributes", IN, TidyKeepLast, ParseRepeatAttr, repeatAttrPicks },
{ TidyAltText, MU, "alt-text", ST, 0, ParseString, NULL }, { TidyAltText, MU, "alt-text", ST, 0, ParseString, NULL },
@ -274,7 +276,6 @@ static const TidyOptionImpl option_defs[] =
{ TidyWord2000, MU, "word-2000", BL, no, ParseBool, boolPicks }, { TidyWord2000, MU, "word-2000", BL, no, ParseBool, boolPicks },
{ TidyMark, MS, "tidy-mark", BL, yes, ParseBool, boolPicks }, { TidyMark, MS, "tidy-mark", BL, yes, ParseBool, boolPicks },
{ TidyEmacs, MS, "gnu-emacs", BL, no, ParseBool, boolPicks }, { TidyEmacs, MS, "gnu-emacs", BL, no, ParseBool, boolPicks },
{ TidyEmacsFile, MS, "gnu-emacs-file", ST, 0, ParseString, NULL },
{ TidyLiteralAttribs, MU, "literal-attributes", BL, no, ParseBool, boolPicks }, { TidyLiteralAttribs, MU, "literal-attributes", BL, no, ParseBool, boolPicks },
{ TidyBodyOnly, MU, "show-body-only", IN, no, ParseAutoBool, autoBoolPicks }, { TidyBodyOnly, MU, "show-body-only", IN, no, ParseAutoBool, autoBoolPicks },
{ TidyFixUri, MU, "fix-uri", BL, yes, ParseBool, boolPicks }, { TidyFixUri, MU, "fix-uri", BL, yes, ParseBool, boolPicks },
@ -904,11 +905,24 @@ Bool TY_(ParseConfigOption)( TidyDocImpl* doc, ctmbstr optnam, ctmbstr optval )
*/ */
Bool TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optval ) Bool TY_(ParseConfigValue)( TidyDocImpl* doc, TidyOptionId optId, ctmbstr optval )
{ {
const TidyOptionImpl* option = option_defs + optId; const TidyOptionImpl* option = NULL;
Bool status = ( optId < N_TIDY_OPTIONS && optval != NULL ); enum { sizeBuf = 11 };
char buffer[sizeBuf];
/* #472: fail status if there is a NULL parser. @ralfjunker */
Bool status = ( optId < N_TIDY_OPTIONS
&& (option = option_defs + optId)->parser
&& optval != NULL );
if ( !status ) if ( !status )
TY_(ReportBadArgument)( doc, option->name ); if ( option )
TY_(ReportBadArgument)(doc, option->name);
else
{
/* If optId < N_TIDY_OPTIONS then option remains unassigned,
and we have to fall back to an ugly error message. */
TY_(tmbsnprintf(buffer, sizeBuf, "%u", optId));
TY_(ReportUnknownOption(doc, buffer));
}
else else
{ {
TidyBuffer inbuf; /* Set up input source */ TidyBuffer inbuf; /* Set up input source */