From 29766afcfd7011382dd16f4d8c2f8d46e87041c8 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Thu, 11 May 2017 18:12:56 -0400 Subject: [PATCH 1/3] Initial take on issue 365. This is based off of the simplification of the parser and picklist system. Console application needs to be updated to fix the description, as it shows autobool, and for some reason on the current system I'm not getting assertion failures. --- include/tidyenum.h | 10 +++ src/config.c | 202 +++++++++++++++++++++++---------------------- src/language_en.h | 8 +- src/lexer.c | 7 +- src/parser.c | 4 +- src/pprint.c | 10 +-- 6 files changed, 133 insertions(+), 108 deletions(-) diff --git a/include/tidyenum.h b/include/tidyenum.h index 0a98511..a2feab6 100644 --- a/include/tidyenum.h +++ b/include/tidyenum.h @@ -786,6 +786,16 @@ typedef enum TidySortAttrAlpha /**< Sort attributes alphabetically */ } TidyAttrSortStrategy; +/** Mode controlling capitalization of things, such as attributes. + ** @remark This enum's starting value is guaranteed to remain stable. + */ +typedef enum +{ + TidyUppercaseNo = 0, /**< Don't uppercase. */ + TidyUppercaseYes, /**< Do uppercase. */ + TidyUppercasePreserve /**< Preserve case. */ +} TidyUppercase; + /** @} ** @name Document Tree diff --git a/src/config.c b/src/config.c index a35becc..9b7424f 100644 --- a/src/config.c +++ b/src/config.c @@ -138,6 +138,14 @@ static PickListItems customTagsPicks = { { NULL } }; +static PickListItems attributeCasePicks = { + { "no", TidyUppercaseNo, { "0", "n", "f", "no", "false", NULL } }, + { "yes", TidyUppercaseYes, { "1", "y", "t", "yes", "true", NULL } }, + { "preserve", TidyUppercasePreserve, { "preserve", NULL } }, + { NULL } +}; + + #define MU TidyMarkup #define DG TidyDiagnostics @@ -198,113 +206,113 @@ static ParseProperty ParsePickList; /* Ensure struct order is same order as tidyenum.h:TidyOptionId! */ static const TidyOptionImpl option_defs[] = { - { TidyUnknownOption, MS, "unknown!", IN, 0, NULL, NULL }, - { TidyAccessibilityCheckLevel, DG, "accessibility-check", IN, 0, ParseAcc, &accessPicks }, - { TidyAltText, MU, "alt-text", ST, 0, ParseString, NULL }, - { TidyAnchorAsName, MU, "anchor-as-name", BL, yes, ParsePickList, &boolPicks }, - { TidyAsciiChars, CE, "ascii-chars", BL, no, ParsePickList, &boolPicks }, - { TidyBlockTags, MU, "new-blocklevel-tags", ST, 0, ParseTagNames, NULL }, - { TidyBodyOnly, MU, "show-body-only", IN, no, ParsePickList, &autoBoolPicks }, - { TidyBreakBeforeBR, PP, "break-before-br", BL, no, ParsePickList, &boolPicks }, - { TidyCharEncoding, CE, "char-encoding", IN, UTF8, ParseCharEnc, &charEncPicks }, - { TidyCoerceEndTags, MU, "coerce-endtags", BL, yes, ParsePickList, &boolPicks }, - { TidyCSSPrefix, MU, "css-prefix", ST, 0, ParseCSS1Selector, NULL }, - { TidyCustomTags, IR, "new-custom-tags", ST, 0, ParseTagNames, NULL }, /* 20170309 - Issue #119 */ - { TidyDecorateInferredUL, MU, "decorate-inferred-ul", BL, no, ParsePickList, &boolPicks }, - { TidyDoctype, MU, "doctype", ST, 0, ParseDocType, &doctypePicks }, + { TidyUnknownOption, MS, "unknown!", IN, 0, NULL, NULL }, + { TidyAccessibilityCheckLevel, DG, "accessibility-check", IN, 0, ParseAcc, &accessPicks }, + { TidyAltText, MU, "alt-text", ST, 0, ParseString, NULL }, + { TidyAnchorAsName, MU, "anchor-as-name", BL, yes, ParsePickList, &boolPicks }, + { TidyAsciiChars, CE, "ascii-chars", BL, no, ParsePickList, &boolPicks }, + { TidyBlockTags, MU, "new-blocklevel-tags", ST, 0, ParseTagNames, NULL }, + { TidyBodyOnly, MU, "show-body-only", IN, no, ParsePickList, &autoBoolPicks }, + { TidyBreakBeforeBR, PP, "break-before-br", BL, no, ParsePickList, &boolPicks }, + { TidyCharEncoding, CE, "char-encoding", IN, UTF8, ParseCharEnc, &charEncPicks }, + { TidyCoerceEndTags, MU, "coerce-endtags", BL, yes, ParsePickList, &boolPicks }, + { TidyCSSPrefix, MU, "css-prefix", ST, 0, ParseCSS1Selector, NULL }, + { TidyCustomTags, IR, "new-custom-tags", ST, 0, ParseTagNames, NULL }, /* 20170309 - Issue #119 */ + { TidyDecorateInferredUL, MU, "decorate-inferred-ul", BL, no, ParsePickList, &boolPicks }, + { TidyDoctype, MU, "doctype", ST, 0, ParseDocType, &doctypePicks }, #ifndef DOXYGEN_SHOULD_SKIP_THIS - { TidyDoctypeMode, IR, "doctype-mode", IN, TidyDoctypeAuto, NULL, &doctypePicks }, + { TidyDoctypeMode, IR, "doctype-mode", IN, TidyDoctypeAuto, NULL, &doctypePicks }, #endif - { TidyDropEmptyElems, MU, "drop-empty-elements", BL, yes, ParsePickList, &boolPicks }, - { TidyDropEmptyParas, MU, "drop-empty-paras", BL, yes, ParsePickList, &boolPicks }, - { TidyDropPropAttrs, MU, "drop-proprietary-attributes", BL, no, ParsePickList, &boolPicks }, - { TidyDuplicateAttrs, MU, "repeated-attributes", IN, TidyKeepLast, ParsePickList, &repeatAttrPicks }, - { TidyEmacs, MS, "gnu-emacs", BL, no, ParsePickList, &boolPicks }, + { TidyDropEmptyElems, MU, "drop-empty-elements", BL, yes, ParsePickList, &boolPicks }, + { TidyDropEmptyParas, MU, "drop-empty-paras", BL, yes, ParsePickList, &boolPicks }, + { TidyDropPropAttrs, MU, "drop-proprietary-attributes", BL, no, ParsePickList, &boolPicks }, + { TidyDuplicateAttrs, MU, "repeated-attributes", IN, TidyKeepLast, ParsePickList, &repeatAttrPicks }, + { TidyEmacs, MS, "gnu-emacs", BL, no, ParsePickList, &boolPicks }, #ifndef DOXYGEN_SHOULD_SKIP_THIS - { TidyEmacsFile, IR, "gnu-emacs-file", ST, 0, ParseString, NULL }, + { TidyEmacsFile, IR, "gnu-emacs-file", ST, 0, ParseString, NULL }, #endif - { TidyEmptyTags, MU, "new-empty-tags", ST, 0, ParseTagNames, NULL }, - { TidyEncloseBlockText, MU, "enclose-block-text", BL, no, ParsePickList, &boolPicks }, - { TidyEncloseBodyText, MU, "enclose-text", BL, no, ParsePickList, &boolPicks }, - { TidyErrFile, MS, "error-file", ST, 0, ParseString, NULL }, - { TidyEscapeCdata, MU, "escape-cdata", BL, no, ParsePickList, &boolPicks }, - { TidyEscapeScripts, PP, "escape-scripts", BL, yes, ParsePickList, &boolPicks }, /* 20160227 - Issue #348 */ - { TidyFixBackslash, MU, "fix-backslash", BL, yes, ParsePickList, &boolPicks }, - { TidyFixComments, MU, "fix-bad-comments", BL, yes, ParsePickList, &boolPicks }, - { TidyFixUri, MU, "fix-uri", BL, yes, ParsePickList, &boolPicks }, - { TidyForceOutput, MS, "force-output", BL, no, ParsePickList, &boolPicks }, - { TidyGDocClean, MU, "gdoc", BL, no, ParsePickList, &boolPicks }, - { TidyHideComments, MU, "hide-comments", BL, no, ParsePickList, &boolPicks }, - { TidyHtmlOut, MU, "output-html", BL, no, ParsePickList, &boolPicks }, - { TidyInCharEncoding, CE, "input-encoding", IN, UTF8, ParseCharEnc, &charEncPicks }, - { TidyIndentAttributes, PP, "indent-attributes", BL, no, ParsePickList, &boolPicks }, - { TidyIndentCdata, MU, "indent-cdata", BL, no, ParsePickList, &boolPicks }, - { TidyIndentContent, PP, "indent", IN, TidyNoState, ParsePickList, &autoBoolPicks }, - { TidyIndentSpaces, PP, "indent-spaces", IN, 2, ParseInt, NULL }, - { TidyInlineTags, MU, "new-inline-tags", ST, 0, ParseTagNames, NULL }, - { TidyJoinClasses, MU, "join-classes", BL, no, ParsePickList, &boolPicks }, - { TidyJoinStyles, MU, "join-styles", BL, yes, ParsePickList, &boolPicks }, - { TidyKeepFileTimes, MS, "keep-time", BL, no, ParsePickList, &boolPicks }, - { TidyLiteralAttribs, MU, "literal-attributes", BL, no, ParsePickList, &boolPicks }, - { TidyLogicalEmphasis, MU, "logical-emphasis", BL, no, ParsePickList, &boolPicks }, - { TidyLowerLiterals, MU, "lower-literals", BL, yes, ParsePickList, &boolPicks }, - { TidyMakeBare, MU, "bare", BL, no, ParsePickList, &boolPicks }, - { TidyMakeClean, MU, "clean", BL, no, ParsePickList, &boolPicks }, - { TidyMark, MS, "tidy-mark", BL, yes, ParsePickList, &boolPicks }, - { TidyMergeDivs, MU, "merge-divs", IN, TidyAutoState, ParsePickList, &autoBoolPicks }, - { TidyMergeEmphasis, MU, "merge-emphasis", BL, yes, ParsePickList, &boolPicks }, - { TidyMergeSpans, MU, "merge-spans", IN, TidyAutoState, ParsePickList, &autoBoolPicks }, + { TidyEmptyTags, MU, "new-empty-tags", ST, 0, ParseTagNames, NULL }, + { TidyEncloseBlockText, MU, "enclose-block-text", BL, no, ParsePickList, &boolPicks }, + { TidyEncloseBodyText, MU, "enclose-text", BL, no, ParsePickList, &boolPicks }, + { TidyErrFile, MS, "error-file", ST, 0, ParseString, NULL }, + { TidyEscapeCdata, MU, "escape-cdata", BL, no, ParsePickList, &boolPicks }, + { TidyEscapeScripts, PP, "escape-scripts", BL, yes, ParsePickList, &boolPicks }, /* 20160227 - Issue #348 */ + { TidyFixBackslash, MU, "fix-backslash", BL, yes, ParsePickList, &boolPicks }, + { TidyFixComments, MU, "fix-bad-comments", BL, yes, ParsePickList, &boolPicks }, + { TidyFixUri, MU, "fix-uri", BL, yes, ParsePickList, &boolPicks }, + { TidyForceOutput, MS, "force-output", BL, no, ParsePickList, &boolPicks }, + { TidyGDocClean, MU, "gdoc", BL, no, ParsePickList, &boolPicks }, + { TidyHideComments, MU, "hide-comments", BL, no, ParsePickList, &boolPicks }, + { TidyHtmlOut, MU, "output-html", BL, no, ParsePickList, &boolPicks }, + { TidyInCharEncoding, CE, "input-encoding", IN, UTF8, ParseCharEnc, &charEncPicks }, + { TidyIndentAttributes, PP, "indent-attributes", BL, no, ParsePickList, &boolPicks }, + { TidyIndentCdata, MU, "indent-cdata", BL, no, ParsePickList, &boolPicks }, + { TidyIndentContent, PP, "indent", IN, TidyNoState, ParsePickList, &autoBoolPicks }, + { TidyIndentSpaces, PP, "indent-spaces", IN, 2, ParseInt, NULL }, + { TidyInlineTags, MU, "new-inline-tags", ST, 0, ParseTagNames, NULL }, + { TidyJoinClasses, MU, "join-classes", BL, no, ParsePickList, &boolPicks }, + { TidyJoinStyles, MU, "join-styles", BL, yes, ParsePickList, &boolPicks }, + { TidyKeepFileTimes, MS, "keep-time", BL, no, ParsePickList, &boolPicks }, + { TidyLiteralAttribs, MU, "literal-attributes", BL, no, ParsePickList, &boolPicks }, + { TidyLogicalEmphasis, MU, "logical-emphasis", BL, no, ParsePickList, &boolPicks }, + { TidyLowerLiterals, MU, "lower-literals", BL, yes, ParsePickList, &boolPicks }, + { TidyMakeBare, MU, "bare", BL, no, ParsePickList, &boolPicks }, + { TidyMakeClean, MU, "clean", BL, no, ParsePickList, &boolPicks }, + { TidyMark, MS, "tidy-mark", BL, yes, ParsePickList, &boolPicks }, + { TidyMergeDivs, MU, "merge-divs", IN, TidyAutoState, ParsePickList, &autoBoolPicks }, + { TidyMergeEmphasis, MU, "merge-emphasis", BL, yes, ParsePickList, &boolPicks }, + { TidyMergeSpans, MU, "merge-spans", IN, TidyAutoState, ParsePickList, &autoBoolPicks }, #if SUPPORT_ASIAN_ENCODINGS - { TidyNCR, MU, "ncr", BL, yes, ParsePickList, &boolPicks }, + { TidyNCR, MU, "ncr", BL, yes, ParsePickList, &boolPicks }, #endif - { TidyNewline, CE, "newline", IN, DLF, ParsePickList, &newlinePicks }, - { TidyNumEntities, MU, "numeric-entities", BL, no, ParsePickList, &boolPicks }, - { TidyOmitOptionalTags, MU, "omit-optional-tags", BL, no, ParsePickList, &boolPicks }, - { TidyOutCharEncoding, CE, "output-encoding", IN, UTF8, ParseCharEnc, &charEncPicks }, - { TidyOutFile, MS, "output-file", ST, 0, ParseString, NULL }, + { TidyNewline, CE, "newline", IN, DLF, ParsePickList, &newlinePicks }, + { TidyNumEntities, MU, "numeric-entities", BL, no, ParsePickList, &boolPicks }, + { TidyOmitOptionalTags, MU, "omit-optional-tags", BL, no, ParsePickList, &boolPicks }, + { TidyOutCharEncoding, CE, "output-encoding", IN, UTF8, ParseCharEnc, &charEncPicks }, + { TidyOutFile, MS, "output-file", ST, 0, ParseString, NULL }, #if SUPPORT_UTF16_ENCODINGS - { TidyOutputBOM, CE, "output-bom", IN, TidyAutoState, ParsePickList, &autoBoolPicks }, + { TidyOutputBOM, CE, "output-bom", IN, TidyAutoState, ParsePickList, &autoBoolPicks }, #endif - { TidyPPrintTabs, PP, "indent-with-tabs", BL, no, ParseTabs, &boolPicks }, /* 20150515 - Issue #108 */ - { TidyPreserveEntities, MU, "preserve-entities", BL, no, ParsePickList, &boolPicks }, - { TidyPreTags, MU, "new-pre-tags", ST, 0, ParseTagNames, NULL }, + { TidyPPrintTabs, PP, "indent-with-tabs", BL, no, ParseTabs, &boolPicks }, /* 20150515 - Issue #108 */ + { TidyPreserveEntities, MU, "preserve-entities", BL, no, ParsePickList, &boolPicks }, + { TidyPreTags, MU, "new-pre-tags", ST, 0, ParseTagNames, NULL }, #if SUPPORT_ASIAN_ENCODINGS - { TidyPunctWrap, PP, "punctuation-wrap", BL, no, ParsePickList, &boolPicks }, + { TidyPunctWrap, PP, "punctuation-wrap", BL, no, ParsePickList, &boolPicks }, #endif - { TidyQuiet, MS, "quiet", BL, no, ParsePickList, &boolPicks }, - { TidyQuoteAmpersand, MU, "quote-ampersand", BL, yes, ParsePickList, &boolPicks }, - { TidyQuoteMarks, MU, "quote-marks", BL, no, ParsePickList, &boolPicks }, - { TidyQuoteNbsp, MU, "quote-nbsp", BL, yes, ParsePickList, &boolPicks }, - { TidyReplaceColor, MU, "replace-color", BL, no, ParsePickList, &boolPicks }, - { TidyShowErrors, DG, "show-errors", IN, 6, ParseInt, NULL }, - { TidyShowInfo, DG, "show-info", BL, yes, ParsePickList, &boolPicks }, - { TidyShowMarkup, PP, "markup", BL, yes, ParsePickList, &boolPicks }, - { TidyShowWarnings, DG, "show-warnings", BL, yes, ParsePickList, &boolPicks }, - { TidySkipNested, MU, "skip-nested", BL, yes, ParsePickList, &boolPicks }, /* 1642186 - Issue #65 */ - { TidySortAttributes, PP, "sort-attributes", IN, TidySortAttrNone,ParsePickList, &sorterPicks }, - { TidyStrictTagsAttr, MU, "strict-tags-attributes", BL, no, ParsePickList, &boolPicks }, /* 20160209 - Issue #350 */ - { TidyTabSize, PP, "tab-size", IN, 8, ParseInt, NULL }, - { TidyUpperCaseAttrs, MU, "uppercase-attributes", BL, no, ParsePickList, &boolPicks }, - { TidyUpperCaseTags, MU, "uppercase-tags", BL, no, ParsePickList, &boolPicks }, - { TidyUseCustomTags, MU, "custom-tags", IN, TidyCustomNo, ParsePickList, &customTagsPicks }, /* 20170309 - Issue #119 */ - { TidyVertSpace, PP, "vertical-space", IN, no, ParsePickList, &autoBoolPicks }, /* #228 - tri option */ - { TidyWarnPropAttrs, MU, "warn-proprietary-attributes", BL, yes, ParsePickList, &boolPicks }, - { TidyWord2000, MU, "word-2000", BL, no, ParsePickList, &boolPicks }, - { TidyWrapAsp, PP, "wrap-asp", BL, yes, ParsePickList, &boolPicks }, - { TidyWrapAttVals, PP, "wrap-attributes", BL, no, ParsePickList, &boolPicks }, - { TidyWrapJste, PP, "wrap-jste", BL, yes, ParsePickList, &boolPicks }, - { TidyWrapLen, PP, "wrap", IN, 68, ParseInt, NULL }, - { TidyWrapPhp, PP, "wrap-php", BL, yes, ParsePickList, &boolPicks }, - { TidyWrapScriptlets, PP, "wrap-script-literals", BL, no, ParsePickList, &boolPicks }, - { TidyWrapSection, PP, "wrap-sections", BL, yes, ParsePickList, &boolPicks }, - { TidyWriteBack, MS, "write-back", BL, no, ParsePickList, &boolPicks }, - { TidyXhtmlOut, MU, "output-xhtml", BL, no, ParsePickList, &boolPicks }, - { TidyXmlDecl, MU, "add-xml-decl", BL, no, ParsePickList, &boolPicks }, - { TidyXmlOut, MU, "output-xml", BL, no, ParsePickList, &boolPicks }, - { TidyXmlPIs, MU, "assume-xml-procins", BL, no, ParsePickList, &boolPicks }, - { TidyXmlSpace, MU, "add-xml-space", BL, no, ParsePickList, &boolPicks }, - { TidyXmlTags, MU, "input-xml", BL, no, ParsePickList, &boolPicks }, - { N_TIDY_OPTIONS, XX, NULL, XY, 0, NULL, NULL } + { TidyQuiet, MS, "quiet", BL, no, ParsePickList, &boolPicks }, + { TidyQuoteAmpersand, MU, "quote-ampersand", BL, yes, ParsePickList, &boolPicks }, + { TidyQuoteMarks, MU, "quote-marks", BL, no, ParsePickList, &boolPicks }, + { TidyQuoteNbsp, MU, "quote-nbsp", BL, yes, ParsePickList, &boolPicks }, + { TidyReplaceColor, MU, "replace-color", BL, no, ParsePickList, &boolPicks }, + { TidyShowErrors, DG, "show-errors", IN, 6, ParseInt, NULL }, + { TidyShowInfo, DG, "show-info", BL, yes, ParsePickList, &boolPicks }, + { TidyShowMarkup, PP, "markup", BL, yes, ParsePickList, &boolPicks }, + { TidyShowWarnings, DG, "show-warnings", BL, yes, ParsePickList, &boolPicks }, + { TidySkipNested, MU, "skip-nested", BL, yes, ParsePickList, &boolPicks }, /* 1642186 - Issue #65 */ + { TidySortAttributes, PP, "sort-attributes", IN, TidySortAttrNone,ParsePickList, &sorterPicks }, + { TidyStrictTagsAttr, MU, "strict-tags-attributes", BL, no, ParsePickList, &boolPicks }, /* 20160209 - Issue #350 */ + { TidyTabSize, PP, "tab-size", IN, 8, ParseInt, NULL }, + { TidyUpperCaseAttrs, MU, "uppercase-attributes", IN, no, ParsePickList, &attributeCasePicks }, + { TidyUpperCaseTags, MU, "uppercase-tags", BL, no, ParsePickList, &boolPicks }, + { TidyUseCustomTags, MU, "custom-tags", IN, TidyCustomNo, ParsePickList, &customTagsPicks }, /* 20170309 - Issue #119 */ + { TidyVertSpace, PP, "vertical-space", IN, no, ParsePickList, &autoBoolPicks }, /* #228 - tri option */ + { TidyWarnPropAttrs, MU, "warn-proprietary-attributes", BL, yes, ParsePickList, &boolPicks }, + { TidyWord2000, MU, "word-2000", BL, no, ParsePickList, &boolPicks }, + { TidyWrapAsp, PP, "wrap-asp", BL, yes, ParsePickList, &boolPicks }, + { TidyWrapAttVals, PP, "wrap-attributes", BL, no, ParsePickList, &boolPicks }, + { TidyWrapJste, PP, "wrap-jste", BL, yes, ParsePickList, &boolPicks }, + { TidyWrapLen, PP, "wrap", IN, 68, ParseInt, NULL }, + { TidyWrapPhp, PP, "wrap-php", BL, yes, ParsePickList, &boolPicks }, + { TidyWrapScriptlets, PP, "wrap-script-literals", BL, no, ParsePickList, &boolPicks }, + { TidyWrapSection, PP, "wrap-sections", BL, yes, ParsePickList, &boolPicks }, + { TidyWriteBack, MS, "write-back", BL, no, ParsePickList, &boolPicks }, + { TidyXhtmlOut, MU, "output-xhtml", BL, no, ParsePickList, &boolPicks }, + { TidyXmlDecl, MU, "add-xml-decl", BL, no, ParsePickList, &boolPicks }, + { TidyXmlOut, MU, "output-xml", BL, no, ParsePickList, &boolPicks }, + { TidyXmlPIs, MU, "assume-xml-procins", BL, no, ParsePickList, &boolPicks }, + { TidyXmlSpace, MU, "add-xml-space", BL, no, ParsePickList, &boolPicks }, + { TidyXmlTags, MU, "input-xml", BL, no, ParsePickList, &boolPicks }, + { N_TIDY_OPTIONS, XX, NULL, XY, 0, NULL, NULL } }; diff --git a/src/language_en.h b/src/language_en.h index ebd33cc..0fccc9d 100644 --- a/src/language_en.h +++ b/src/language_en.h @@ -1202,8 +1202,12 @@ static languageDefinition language_en = { whichPluralForm_en, { "This option specifies if Tidy should output attribute names in upper " "case. " "
" - "The default is no, which results in lower case attribute " - "names, except for XML input, where the original case is preserved. " + "When set to no, attribute names will be written in lower " + "case. Specifying yes will output attribute names in upper " + "case, and preserve can used to leave attribute names " + "untouched. " + "
" + "When using XML input, the original case is always preserved. " }, {/* Important notes for translators: - Use only , , , , and diff --git a/src/lexer.c b/src/lexer.c index 238fbfa..4fed7dc 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -3726,8 +3726,11 @@ static tmbstr ParseAttribute( TidyDocImpl* doc, Bool *isempty, /* what should be done about non-namechar characters? */ /* currently these are incorporated into the attr name */ - if ( !cfgBool(doc, TidyXmlTags) && TY_(IsUpper)(c) ) - c = TY_(ToLower)(c); + if ( cfg(doc, TidyUpperCaseAttrs) != TidyUppercasePreserve ) + { + if ( !cfgBool(doc, TidyXmlTags) && TY_(IsUpper)(c) ) + c = TY_(ToLower)(c); + } TY_(AddCharToLexer)( lexer, c ); lastc = c; diff --git a/src/parser.c b/src/parser.c index 9023ba6..1bda019 100644 --- a/src/parser.c +++ b/src/parser.c @@ -4832,8 +4832,8 @@ void TY_(ParseDocument)(TidyDocImpl* doc) /* adjust other config options, just as in config.c */ if ( !htmlOut ) { - TY_(SetOptionBool)( doc, TidyUpperCaseTags, no ); - TY_(SetOptionBool)( doc, TidyUpperCaseAttrs, no ); + TY_(SetOptionInt)( doc, TidyUpperCaseTags, no ); + TY_(SetOptionInt)( doc, TidyUpperCaseAttrs, no ); } } } diff --git a/src/pprint.c b/src/pprint.c index a6d2186..747c381 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -1238,7 +1238,7 @@ static void PPrintAttribute( TidyDocImpl* doc, uint indent, Bool xmlOut = cfgBool( doc, TidyXmlOut ); Bool xhtmlOut = cfgBool( doc, TidyXhtmlOut ); Bool wrapAttrs = cfgBool( doc, TidyWrapAttVals ); - Bool ucAttrs = cfgBool( doc, TidyUpperCaseAttrs ); + uint ucAttrs = cfgBool( doc, TidyUpperCaseAttrs ); Bool indAttrs = cfgBool( doc, TidyIndentAttributes ); uint xtra = AttrIndent( doc, node, attr ); Bool first = AttrNoIndentFirst( /*doc,*/ node, attr ); @@ -1287,7 +1287,7 @@ static void PPrintAttribute( TidyDocImpl* doc, uint indent, if (c > 0x7F) name += TY_(GetUTF8)(name, &c); - else if (ucAttrs) + else if (ucAttrs == TidyUppercaseYes) c = TY_(ToUpper)(c); AddChar(pprint, c); @@ -1734,8 +1734,8 @@ static void PPrintXmlDecl( TidyDocImpl* doc, uint indent, Node *node ) saveWrap = WrapOff( doc ); /* no case translation for XML declaration pseudo attributes */ - ucAttrs = cfgBool(doc, TidyUpperCaseAttrs); - TY_(SetOptionBool)(doc, TidyUpperCaseAttrs, no); + ucAttrs = cfg(doc, TidyUpperCaseAttrs); + TY_(SetOptionInt)(doc, TidyUpperCaseAttrs, no); AddString( pprint, "end <= 0 || doc->lexer->lexbuf[node->end - 1] != '?' ) AddChar( pprint, '?' ); From e7c28636b9a6f807d5358a974c976e515ea86164 Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Fri, 12 May 2017 07:30:20 -0400 Subject: [PATCH 2/3] Fixed cause of assertions -- funny, these don't pop up in XCode. --- src/config.c | 4 ++-- src/parser.c | 2 +- src/pprint.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/config.c b/src/config.c index 9b7424f..17655ed 100644 --- a/src/config.c +++ b/src/config.c @@ -292,7 +292,7 @@ static const TidyOptionImpl option_defs[] = { TidySortAttributes, PP, "sort-attributes", IN, TidySortAttrNone,ParsePickList, &sorterPicks }, { TidyStrictTagsAttr, MU, "strict-tags-attributes", BL, no, ParsePickList, &boolPicks }, /* 20160209 - Issue #350 */ { TidyTabSize, PP, "tab-size", IN, 8, ParseInt, NULL }, - { TidyUpperCaseAttrs, MU, "uppercase-attributes", IN, no, ParsePickList, &attributeCasePicks }, + { TidyUpperCaseAttrs, MU, "uppercase-attributes", IN, TidyUppercaseNo, ParsePickList, &attributeCasePicks }, { TidyUpperCaseTags, MU, "uppercase-tags", BL, no, ParsePickList, &boolPicks }, { TidyUseCustomTags, MU, "custom-tags", IN, TidyCustomNo, ParsePickList, &customTagsPicks }, /* 20170309 - Issue #119 */ { TidyVertSpace, PP, "vertical-space", IN, no, ParsePickList, &autoBoolPicks }, /* #228 - tri option */ @@ -1034,7 +1034,7 @@ void AdjustConfig( TidyDocImpl* doc ) { TY_(SetOptionBool)( doc, TidyXmlOut, yes ); TY_(SetOptionBool)( doc, TidyUpperCaseTags, no ); - TY_(SetOptionBool)( doc, TidyUpperCaseAttrs, no ); + TY_(SetOptionInt)( doc, TidyUpperCaseAttrs, no ); /* TY_(SetOptionBool)( doc, TidyXmlPIs, yes ); */ } diff --git a/src/parser.c b/src/parser.c index 1bda019..a037280 100644 --- a/src/parser.c +++ b/src/parser.c @@ -4832,7 +4832,7 @@ void TY_(ParseDocument)(TidyDocImpl* doc) /* adjust other config options, just as in config.c */ if ( !htmlOut ) { - TY_(SetOptionInt)( doc, TidyUpperCaseTags, no ); + TY_(SetOptionBool)( doc, TidyUpperCaseTags, no ); TY_(SetOptionInt)( doc, TidyUpperCaseAttrs, no ); } } diff --git a/src/pprint.c b/src/pprint.c index 747c381..9106396 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -1238,7 +1238,7 @@ static void PPrintAttribute( TidyDocImpl* doc, uint indent, Bool xmlOut = cfgBool( doc, TidyXmlOut ); Bool xhtmlOut = cfgBool( doc, TidyXhtmlOut ); Bool wrapAttrs = cfgBool( doc, TidyWrapAttVals ); - uint ucAttrs = cfgBool( doc, TidyUpperCaseAttrs ); + uint ucAttrs = cfg( doc, TidyUpperCaseAttrs ); Bool indAttrs = cfgBool( doc, TidyIndentAttributes ); uint xtra = AttrIndent( doc, node, attr ); Bool first = AttrNoIndentFirst( /*doc,*/ node, attr ); From 982504eee0612c0cb9772afa9ef0a33a31f7f1fc Mon Sep 17 00:00:00 2001 From: Jim Derry Date: Fri, 12 May 2017 08:28:11 -0400 Subject: [PATCH 3/3] Case insensitive compare is safe here, and prevents erroneous propriertary attribute errors. --- src/attrs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/attrs.c b/src/attrs.c index 4f1c449..bfdca57 100644 --- a/src/attrs.c +++ b/src/attrs.c @@ -824,15 +824,15 @@ static const Attribute* attrsLookup(TidyDocImpl* doc, #if ATTRIBUTE_HASH_LOOKUP for (p = attribs->hashtab[attrsHash(atnam)]; p && p->attr; p = p->next) - if (TY_(tmbstrcmp)(atnam, p->attr->name) == 0) + if (TY_(tmbstrcasecmp)(atnam, p->attr->name) == 0) return p->attr; for (np = attribute_defs; np && np->name; ++np) - if (TY_(tmbstrcmp)(atnam, np->name) == 0) + if (TY_(tmbstrcasecmp)(atnam, np->name) == 0) return attrsInstall(doc, attribs, np); #else for (np = attribute_defs; np && np->name; ++np) - if (TY_(tmbstrcmp)(atnam, np->name) == 0) + if (TY_(tmbstrcasecmp)(atnam, np->name) == 0) return np; #endif