From 04225966c5aa60e418f023b5a2032e1b871bcc4e Mon Sep 17 00:00:00 2001 From: Swapnadeep Som <90515154+GawdOfROFL@users.noreply.github.com> Date: Wed, 29 Sep 2021 14:36:13 +0530 Subject: [PATCH] Few minor changes to the repo to make it look better (#31) * cleaned the repo * delete pycaches * Add new generation after each iteration * ability to read template and rules if run from outside the domato directory * changes in the code according to the comments * few more changes according to the comments * delete pycaches * readd mistakenly removed info * added info to the new main file as well * rename functions * reduce time complexity * added correct info headers * add result var inside the if statement * commit to make the changes in the follow up inline comments * rename generate_sample to generate_samples * pycaches again * added comments on the svg and html tags file * follow up changes * spaces --- README.md | 6 +- generator.py | 349 +++--------------- html_tags.py | 156 ++++++++ .../attributevalues.txt | 0 common.txt => rules/common.txt | 0 css.txt => rules/css.txt | 0 cssproperties.txt => rules/cssproperties.txt | 0 html.txt => rules/html.txt | 0 js.txt => rules/js.txt | 0 jshelpers.txt => rules/jshelpers.txt | 0 svg.txt => rules/svg.txt | 0 svgattrvalues.txt => rules/svgattrvalues.txt | 0 tagattributes.txt => rules/tagattributes.txt | 0 svg_tags.py | 109 ++++++ 14 files changed, 328 insertions(+), 292 deletions(-) create mode 100644 html_tags.py rename attributevalues.txt => rules/attributevalues.txt (100%) rename common.txt => rules/common.txt (100%) rename css.txt => rules/css.txt (100%) rename cssproperties.txt => rules/cssproperties.txt (100%) rename html.txt => rules/html.txt (100%) rename js.txt => rules/js.txt (100%) rename jshelpers.txt => rules/jshelpers.txt (100%) rename svg.txt => rules/svg.txt (100%) rename svgattrvalues.txt => rules/svgattrvalues.txt (100%) rename tagattributes.txt => rules/tagattributes.txt (100%) create mode 100644 svg_tags.py diff --git a/README.md b/README.md index 9ff4dcb..4105dec 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,13 @@ limitations under the License. #### Usage +To see the usage information run the following command: + +`python3 generator.py --help` + To generate a single .html sample run: -`python generator.py ` +`python generator.py --file ` To generate multiple samples with a single call run: diff --git a/generator.py b/generator.py index 5ca9da9..055e23d 100755 --- a/generator.py +++ b/generator.py @@ -1,5 +1,5 @@ # Domato - main generator script -# ------------------------------- +# -------------------------------------- # # Written and maintained by Ivan Fratric # @@ -21,247 +21,17 @@ import os import re import random -import sys +import argparse from grammar import Grammar +from svg_tags import _SVG_TYPES +from html_tags import _HTML_TYPES _N_MAIN_LINES = 1000 _N_EVENTHANDLER_LINES = 500 _N_ADDITIONAL_HTMLVARS = 5 -# A map from tag name to corresponding type for HTML tags -_HTML_TYPES = { - 'a': 'HTMLAnchorElement', - 'abbr': 'HTMLUnknownElement', - 'acronym': 'HTMLUnknownElement', - 'address': 'HTMLUnknownElement', - 'applet': 'HTMLUnknownElement', - 'area': 'HTMLAreaElement', - 'article': 'HTMLUnknownElement', - 'aside': 'HTMLUnknownElement', - 'audio': 'HTMLAudioElement', - 'b': 'HTMLUnknownElement', - 'base': 'HTMLBaseElement', - 'basefont': 'HTMLUnknownElement', - 'bdi': 'HTMLUnknownElement', - 'bdo': 'HTMLUnknownElement', - 'bgsound': 'HTMLUnknownElement', - 'big': 'HTMLUnknownElement', - 'blockquote': 'HTMLUnknownElement', - 'br': 'HTMLBRElement', - 'button': 'HTMLButtonElement', - 'canvas': 'HTMLCanvasElement', - 'caption': 'HTMLTableCaptionElement', - 'center': 'HTMLUnknownElement', - 'cite': 'HTMLUnknownElement', - 'code': 'HTMLUnknownElement', - 'col': 'HTMLTableColElement', - 'colgroup': 'HTMLUnknownElement', - 'command': 'HTMLUnknownElement', - 'content': 'HTMLContentElement', - 'data': 'HTMLDataElement', - 'datalist': 'HTMLDataListElement', - 'dd': 'HTMLUnknownElement', - 'del': 'HTMLModElement', - 'details': 'HTMLDetailsElement', - 'dfn': 'HTMLUnknownElement', - 'dialog': 'HTMLDialogElement', - 'dir': 'HTMLDirectoryElement', - 'div': 'HTMLDivElement', - 'dl': 'HTMLDListElement', - 'dt': 'HTMLUnknownElement', - 'em': 'HTMLUnknownElement', - 'embed': 'HTMLEmbedElement', - 'fieldset': 'HTMLFieldSetElement', - 'figcaption': 'HTMLUnknownElement', - 'figure': 'HTMLUnknownElement', - 'font': 'HTMLFontElement', - 'footer': 'HTMLUnknownElement', - 'form': 'HTMLFormElement', - 'frame': 'HTMLFrameElement', - 'frameset': 'HTMLFrameSetElement', - 'h1': 'HTMLHeadingElement', - 'h2': 'HTMLHeadingElement', - 'h3': 'HTMLHeadingElement', - 'h4': 'HTMLHeadingElement', - 'h5': 'HTMLHeadingElement', - 'h6': 'HTMLHeadingElement', - 'header': 'HTMLUnknownElement', - 'hgroup': 'HTMLUnknownElement', - 'hr': 'HTMLHRElement', - 'i': 'HTMLUnknownElement', - 'iframe': 'HTMLIFrameElement', - 'image': 'HTMLImageElement', - 'img': 'HTMLImageElement', - 'input': 'HTMLInputElement', - 'ins': 'HTMLModElement', - 'isindex': 'HTMLUnknownElement', - 'kbd': 'HTMLUnknownElement', - 'keygen': 'HTMLKeygenElement', - 'label': 'HTMLLabelElement', - 'layer': 'HTMLUnknownElement', - 'legend': 'HTMLLegendElement', - 'li': 'HTMLLIElement', - 'link': 'HTMLLinkElement', - 'listing': 'HTMLUnknownElement', - 'main': 'HTMLUnknownElement', - 'map': 'HTMLMapElement', - 'mark': 'HTMLUnknownElement', - 'marquee': 'HTMLMarqueeElement', - 'menu': 'HTMLMenuElement', - 'menuitem': 'HTMLMenuItemElement', - 'meta': 'HTMLMetaElement', - 'meter': 'HTMLMeterElement', - 'nav': 'HTMLUnknownElement', - 'nobr': 'HTMLUnknownElement', - 'noembed': 'HTMLUnknownElement', - 'noframes': 'HTMLUnknownElement', - 'nolayer': 'HTMLUnknownElement', - 'noscript': 'HTMLUnknownElement', - 'object': 'HTMLObjectElement', - 'ol': 'HTMLOListElement', - 'optgroup': 'HTMLOptGroupElement', - 'option': 'HTMLOptionElement', - 'output': 'HTMLOutputElement', - 'p': 'HTMLParagraphElement', - 'param': 'HTMLParamElement', - 'picture': 'HTMLPictureElement', - 'plaintext': 'HTMLUnknownElement', - 'pre': 'HTMLPreElement', - 'progress': 'HTMLProgressElement', - 'q': 'HTMLQuoteElement', - 'rp': 'HTMLUnknownElement', - 'rt': 'HTMLUnknownElement', - 'ruby': 'HTMLUnknownElement', - 's': 'HTMLUnknownElement', - 'samp': 'HTMLUnknownElement', - 'section': 'HTMLUnknownElement', - 'select': 'HTMLSelectElement', - 'shadow': 'HTMLShadowElement', - 'small': 'HTMLUnknownElement', - 'source': 'HTMLSourceElement', - 'span': 'HTMLSpanElement', - 'strike': 'HTMLUnknownElement', - 'strong': 'HTMLUnknownElement', - 'style': 'HTMLStyleElement', - 'sub': 'HTMLUnknownElement', - 'summary': 'HTMLUnknownElement', - 'sup': 'HTMLUnknownElement', - 'table': 'HTMLTableElement', - 'tbody': 'HTMLTableSectionElement', - 'td': 'HTMLUnknownElement', - 'template': 'HTMLTemplateElement', - 'textarea': 'HTMLTextAreaElement', - 'tfoot': 'HTMLTableSectionElement', - 'th': 'HTMLTableCellElement', - 'thead': 'HTMLTableSectionElement', - 'time': 'HTMLTimeElement', - 'title': 'HTMLTitleElement', - 'tr': 'HTMLTableRowElement', - 'track': 'HTMLTrackElement', - 'tt': 'HTMLUnknownElement', - 'u': 'HTMLUnknownElement', - 'ul': 'HTMLUListElement', - 'var': 'HTMLUnknownElement', - 'video': 'HTMLVideoElement', - 'wbr': 'HTMLUnknownElement', - 'xmp': 'HTMLUnknownElement' -} - -# A map from tag name to corresponding type for SVG tags -_SVG_TYPES = { - 'a': 'SVGAElement', - 'altGlyph': 'SVGElement', - 'altGlyphDef': 'SVGElement', - 'altGlyphItem': 'SVGElement', - 'animate': 'SVGAnimateElement', - 'animateColor': 'SVGElement', - 'animateMotion': 'SVGAnimateMotionElement', - 'animateTransform': 'SVGAnimateTransformElement', - 'circle': 'SVGCircleElement', - 'clipPath': 'SVGClipPathElement', - 'color-profile': 'SVGElement', - 'cursor': 'SVGCursorElement', - 'defs': 'SVGDefsElement', - 'desc': 'SVGDescElement', - 'discard': 'SVGDiscardElement', - 'ellipse': 'SVGEllipseElement', - 'feBlend': 'SVGFEBlendElement', - 'feColorMatrix': 'SVGFEColorMatrixElement', - 'feComponentTransfer': 'SVGFEComponentTransferElement', - 'feComposite': 'SVGFECompositeElement', - 'feConvolveMatrix': 'SVGFEConvolveMatrixElement', - 'feDiffuseLighting': 'SVGFEDiffuseLightingElement', - 'feDisplacementMap': 'SVGFEDisplacementMapElement', - 'feDistantLight': 'SVGFEDistantLightElement', - 'feDropShadow': 'SVGFEDropShadowElement', - 'feFlood': 'SVGFEFloodElement', - 'feFuncA': 'SVGFEFuncAElement', - 'feFuncB': 'SVGFEFuncBElement', - 'feFuncG': 'SVGFEFuncGElement', - 'feFuncR': 'SVGFEFuncRElement', - 'feGaussianBlur': 'SVGFEGaussianBlurElement', - 'feImage': 'SVGFEImageElement', - 'feMerge': 'SVGFEMergeElement', - 'feMergeNode': 'SVGFEMergeNodeElement', - 'feMorphology': 'SVGFEMorphologyElement', - 'feOffset': 'SVGFEOffsetElement', - 'fePointLight': 'SVGFEPointLightElement', - 'feSpecularLighting': 'SVGFESpecularLightingElement', - 'feSpotLight': 'SVGFESpotLightElement', - 'feTile': 'SVGFETileElement', - 'feTurbulence': 'SVGFETurbulenceElement', - 'filter': 'SVGFilterElement', - 'font': 'SVGElement', - 'font-face': 'SVGElement', - 'font-face-format': 'SVGElement', - 'font-face-name': 'SVGElement', - 'font-face-src': 'SVGElement', - 'font-face-uri': 'SVGElement', - 'foreignObject': 'SVGForeignObjectElement', - 'g': 'SVGGElement', - 'glyph': 'SVGElement', - 'glyphRef': 'SVGElement', - 'hatch': 'SVGElement', - 'hatchpath': 'SVGElement', - 'hkern': 'SVGElement', - 'image': 'SVGImageElement', - 'line': 'SVGLineElement', - 'linearGradient': 'SVGLinearGradientElement', - 'marker': 'SVGMarkerElement', - 'mask': 'SVGMaskElement', - 'mesh': 'SVGElement', - 'meshgradient': 'SVGElement', - 'meshpatch': 'SVGElement', - 'meshrow': 'SVGElement', - 'metadata': 'SVGMetadataElement', - 'missing-glyph': 'SVGElement', - 'mpath': 'SVGMPathElement', - 'path': 'SVGPathElement', - 'pattern': 'SVGPatternElement', - 'polygon': 'SVGPolygonElement', - 'polyline': 'SVGPolylineElement', - 'radialGradient': 'SVGRadialGradientElement', - 'rect': 'SVGRectElement', - 'set': 'SVGSetElement', - 'svg': 'SVGSVGElement', - 'solidcolor': 'SVGElement', - 'stop': 'SVGStopElement', - 'switch': 'SVGSwitchElement', - 'symbol': 'SVGSymbolElement', - 'text': 'SVGTextElement', - 'textPath': 'SVGTextPathElement', - 'title': 'SVGTitleElement', - 'tref': 'SVGElement', - 'tspan': 'SVGTSpanElement', - 'unknown': 'SVGElement', - 'use': 'SVGUseElement', - 'view': 'SVGViewElement', - 'vkern': 'SVGElement' -} - - def generate_html_elements(ctx, n): for i in range(n): tag = random.choice(list(_HTML_TYPES)) @@ -304,7 +74,6 @@ def generate_function_body(jsgrammar, htmlctx, num_lines): def check_grammar(grammar): """Checks if grammar has errors and if so outputs them. - Args: grammar: The grammar to check. """ @@ -321,13 +90,11 @@ def check_grammar(grammar): def generate_new_sample(template, htmlgrammar, cssgrammar, jsgrammar): """Parses grammar rules from string. - Args: template: A template string. htmlgrammar: Grammar for generating HTML code. cssgrammar: Grammar for generating CSS code. jsgrammar: Grammar for generating JS code. - Returns: A string containing sample data. """ @@ -368,38 +135,34 @@ def generate_new_sample(template, htmlgrammar, cssgrammar, jsgrammar): return result - -def generate_samples(grammar_dir, outfiles): +def generate_samples(template, outfiles): """Generates a set of samples and writes them to the output files. - Args: grammar_dir: directory to load grammar files from. outfiles: A list of output filenames. """ - f = open(os.path.join(grammar_dir, 'template.html')) - template = f.read() - f.close() - + grammar_dir = os.path.join(os.path.dirname(__file__), 'rules') htmlgrammar = Grammar() + err = htmlgrammar.parse_from_file(os.path.join(grammar_dir, 'html.txt')) # CheckGrammar(htmlgrammar) if err > 0: - print('There were errors parsing grammar') + print('There were errors parsing html grammar') return cssgrammar = Grammar() - err = cssgrammar.parse_from_file(os.path.join(grammar_dir, 'css.txt')) + err = cssgrammar.parse_from_file(os.path.join(grammar_dir ,'css.txt')) # CheckGrammar(cssgrammar) if err > 0: - print('There were errors parsing grammar') + print('There were errors parsing css grammar') return jsgrammar = Grammar() - err = jsgrammar.parse_from_file(os.path.join(grammar_dir, 'js.txt')) + err = jsgrammar.parse_from_file(os.path.join(grammar_dir,'js.txt')) # CheckGrammar(jsgrammar) if err > 0: - print('There were errors parsing grammar') + print('There were errors parsing js grammar') return # JS and HTML grammar need access to CSS grammar. @@ -408,66 +171,70 @@ def generate_samples(grammar_dir, outfiles): jsgrammar.add_import('cssgrammar', cssgrammar) for outfile in outfiles: - result = generate_new_sample(template, htmlgrammar, cssgrammar, - jsgrammar) - + result = generate_new_sample(template, htmlgrammar, cssgrammar, jsgrammar) if result is not None: print('Writing a sample to ' + outfile) try: - f = open(outfile, 'w') - f.write(result) - f.close() + with open(outfile, 'w') as f: + f.write(result) + f.close() except IOError: print('Error writing to output') +def get_argument_parser(): + + parser = argparse.ArgumentParser(description="DOMATO (A DOM FUZZER)") + + parser.add_argument("-f", "--file", + help="File name which is to be generated in the same directory") -def get_option(option_name): - for i in range(len(sys.argv)): - if (sys.argv[i] == option_name) and ((i + 1) < len(sys.argv)): - return sys.argv[i + 1] - elif sys.argv[i].startswith(option_name + '='): - return sys.argv[i][len(option_name) + 1:] - return None - - -def main(): - fuzzer_dir = os.path.dirname(__file__) + parser.add_argument('-o', '--output_dir', type=str, + help='The output directory to put the generated files in') - multiple_samples = False + parser.add_argument('-n', '--no_of_files', type=int, + help='number of files to be generated') - for a in sys.argv: - if a.startswith('--output_dir='): - multiple_samples = True + return parser - if '--output_dir' in sys.argv: - multiple_samples = True +def main(): - if multiple_samples: - print('Running on ClusterFuzz') - out_dir = get_option('--output_dir') - nsamples = int(get_option('--no_of_files')) - print('Output directory: ' + out_dir) - print('Number of samples: ' + str(nsamples)) + fuzzer_dir = os.path.dirname(__file__) - if not os.path.exists(out_dir): - os.mkdir(out_dir) + with open(os.path.join(fuzzer_dir, "template.html"), "r") as f: + template = f.read() + f.close() - outfiles = [] - for i in range(nsamples): - outfiles.append(os.path.join(out_dir, 'fuzz-' + str(i).zfill(5) + '.html')) + parser = get_argument_parser() + + args = parser.parse_args() - generate_samples(fuzzer_dir, outfiles) + if args.file: + generate_samples(template, [args.file]) - elif len(sys.argv) > 1: - outfile = sys.argv[1] - generate_samples(fuzzer_dir, [outfile]) + elif args.output_dir: + if not args.no_of_files: + print("Please use switch -n to specify the number of files") + else: + print('Running on ClusterFuzz') + out_dir = args.output_dir + nsamples = args.no_of_files + print('Output directory: ' + out_dir) + print('Number of samples: ' + str(nsamples)) + + if not os.path.exists(out_dir): + os.mkdir(out_dir) + + outfiles = [] + for i in range(nsamples): + outfiles.append(os.path.join(out_dir, 'fuzz-' + str(i).zfill(5) + '.html')) + + generate_samples(template, outfiles) + else: - print('Arguments missing') - print("Usage:") - print("\tpython generator.py ") - print("\tpython generator.py --output_dir --no_of_files ") + parser.print_help() if __name__ == '__main__': + main() diff --git a/html_tags.py b/html_tags.py new file mode 100644 index 0000000..37928ec --- /dev/null +++ b/html_tags.py @@ -0,0 +1,156 @@ +# Domato - HTML types +# -------------------------------------- +# +# Written and maintained by Ivan Fratric +# +# Copyright 2017 Google Inc. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A map from tag name to corresponding type for HTML tags +_HTML_TYPES = { + 'a': 'HTMLAnchorElement', + 'abbr': 'HTMLUnknownElement', + 'acronym': 'HTMLUnknownElement', + 'address': 'HTMLUnknownElement', + 'applet': 'HTMLUnknownElement', + 'area': 'HTMLAreaElement', + 'article': 'HTMLUnknownElement', + 'aside': 'HTMLUnknownElement', + 'audio': 'HTMLAudioElement', + 'b': 'HTMLUnknownElement', + 'base': 'HTMLBaseElement', + 'basefont': 'HTMLUnknownElement', + 'bdi': 'HTMLUnknownElement', + 'bdo': 'HTMLUnknownElement', + 'bgsound': 'HTMLUnknownElement', + 'big': 'HTMLUnknownElement', + 'blockquote': 'HTMLUnknownElement', + 'br': 'HTMLBRElement', + 'button': 'HTMLButtonElement', + 'canvas': 'HTMLCanvasElement', + 'caption': 'HTMLTableCaptionElement', + 'center': 'HTMLUnknownElement', + 'cite': 'HTMLUnknownElement', + 'code': 'HTMLUnknownElement', + 'col': 'HTMLTableColElement', + 'colgroup': 'HTMLUnknownElement', + 'command': 'HTMLUnknownElement', + 'content': 'HTMLContentElement', + 'data': 'HTMLDataElement', + 'datalist': 'HTMLDataListElement', + 'dd': 'HTMLUnknownElement', + 'del': 'HTMLModElement', + 'details': 'HTMLDetailsElement', + 'dfn': 'HTMLUnknownElement', + 'dialog': 'HTMLDialogElement', + 'dir': 'HTMLDirectoryElement', + 'div': 'HTMLDivElement', + 'dl': 'HTMLDListElement', + 'dt': 'HTMLUnknownElement', + 'em': 'HTMLUnknownElement', + 'embed': 'HTMLEmbedElement', + 'fieldset': 'HTMLFieldSetElement', + 'figcaption': 'HTMLUnknownElement', + 'figure': 'HTMLUnknownElement', + 'font': 'HTMLFontElement', + 'footer': 'HTMLUnknownElement', + 'form': 'HTMLFormElement', + 'frame': 'HTMLFrameElement', + 'frameset': 'HTMLFrameSetElement', + 'h1': 'HTMLHeadingElement', + 'h2': 'HTMLHeadingElement', + 'h3': 'HTMLHeadingElement', + 'h4': 'HTMLHeadingElement', + 'h5': 'HTMLHeadingElement', + 'h6': 'HTMLHeadingElement', + 'header': 'HTMLUnknownElement', + 'hgroup': 'HTMLUnknownElement', + 'hr': 'HTMLHRElement', + 'i': 'HTMLUnknownElement', + 'iframe': 'HTMLIFrameElement', + 'image': 'HTMLImageElement', + 'img': 'HTMLImageElement', + 'input': 'HTMLInputElement', + 'ins': 'HTMLModElement', + 'isindex': 'HTMLUnknownElement', + 'kbd': 'HTMLUnknownElement', + 'keygen': 'HTMLKeygenElement', + 'label': 'HTMLLabelElement', + 'layer': 'HTMLUnknownElement', + 'legend': 'HTMLLegendElement', + 'li': 'HTMLLIElement', + 'link': 'HTMLLinkElement', + 'listing': 'HTMLUnknownElement', + 'main': 'HTMLUnknownElement', + 'map': 'HTMLMapElement', + 'mark': 'HTMLUnknownElement', + 'marquee': 'HTMLMarqueeElement', + 'menu': 'HTMLMenuElement', + 'menuitem': 'HTMLMenuItemElement', + 'meta': 'HTMLMetaElement', + 'meter': 'HTMLMeterElement', + 'nav': 'HTMLUnknownElement', + 'nobr': 'HTMLUnknownElement', + 'noembed': 'HTMLUnknownElement', + 'noframes': 'HTMLUnknownElement', + 'nolayer': 'HTMLUnknownElement', + 'noscript': 'HTMLUnknownElement', + 'object': 'HTMLObjectElement', + 'ol': 'HTMLOListElement', + 'optgroup': 'HTMLOptGroupElement', + 'option': 'HTMLOptionElement', + 'output': 'HTMLOutputElement', + 'p': 'HTMLParagraphElement', + 'param': 'HTMLParamElement', + 'picture': 'HTMLPictureElement', + 'plaintext': 'HTMLUnknownElement', + 'pre': 'HTMLPreElement', + 'progress': 'HTMLProgressElement', + 'q': 'HTMLQuoteElement', + 'rp': 'HTMLUnknownElement', + 'rt': 'HTMLUnknownElement', + 'ruby': 'HTMLUnknownElement', + 's': 'HTMLUnknownElement', + 'samp': 'HTMLUnknownElement', + 'section': 'HTMLUnknownElement', + 'select': 'HTMLSelectElement', + 'shadow': 'HTMLShadowElement', + 'small': 'HTMLUnknownElement', + 'source': 'HTMLSourceElement', + 'span': 'HTMLSpanElement', + 'strike': 'HTMLUnknownElement', + 'strong': 'HTMLUnknownElement', + 'style': 'HTMLStyleElement', + 'sub': 'HTMLUnknownElement', + 'summary': 'HTMLUnknownElement', + 'sup': 'HTMLUnknownElement', + 'table': 'HTMLTableElement', + 'tbody': 'HTMLTableSectionElement', + 'td': 'HTMLUnknownElement', + 'template': 'HTMLTemplateElement', + 'textarea': 'HTMLTextAreaElement', + 'tfoot': 'HTMLTableSectionElement', + 'th': 'HTMLTableCellElement', + 'thead': 'HTMLTableSectionElement', + 'time': 'HTMLTimeElement', + 'title': 'HTMLTitleElement', + 'tr': 'HTMLTableRowElement', + 'track': 'HTMLTrackElement', + 'tt': 'HTMLUnknownElement', + 'u': 'HTMLUnknownElement', + 'ul': 'HTMLUListElement', + 'var': 'HTMLUnknownElement', + 'video': 'HTMLVideoElement', + 'wbr': 'HTMLUnknownElement', + 'xmp': 'HTMLUnknownElement' +} diff --git a/attributevalues.txt b/rules/attributevalues.txt similarity index 100% rename from attributevalues.txt rename to rules/attributevalues.txt diff --git a/common.txt b/rules/common.txt similarity index 100% rename from common.txt rename to rules/common.txt diff --git a/css.txt b/rules/css.txt similarity index 100% rename from css.txt rename to rules/css.txt diff --git a/cssproperties.txt b/rules/cssproperties.txt similarity index 100% rename from cssproperties.txt rename to rules/cssproperties.txt diff --git a/html.txt b/rules/html.txt similarity index 100% rename from html.txt rename to rules/html.txt diff --git a/js.txt b/rules/js.txt similarity index 100% rename from js.txt rename to rules/js.txt diff --git a/jshelpers.txt b/rules/jshelpers.txt similarity index 100% rename from jshelpers.txt rename to rules/jshelpers.txt diff --git a/svg.txt b/rules/svg.txt similarity index 100% rename from svg.txt rename to rules/svg.txt diff --git a/svgattrvalues.txt b/rules/svgattrvalues.txt similarity index 100% rename from svgattrvalues.txt rename to rules/svgattrvalues.txt diff --git a/tagattributes.txt b/rules/tagattributes.txt similarity index 100% rename from tagattributes.txt rename to rules/tagattributes.txt diff --git a/svg_tags.py b/svg_tags.py new file mode 100644 index 0000000..b96589f --- /dev/null +++ b/svg_tags.py @@ -0,0 +1,109 @@ +# Domato - SVG types +# -------------------------------------- +# +# Written and maintained by Ivan Fratric +# +# Copyright 2017 Google Inc. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A map from tag name to corresponding type for SVG tags +_SVG_TYPES = { + 'a': 'SVGAElement', + 'altGlyph': 'SVGElement', + 'altGlyphDef': 'SVGElement', + 'altGlyphItem': 'SVGElement', + 'animate': 'SVGAnimateElement', + 'animateColor': 'SVGElement', + 'animateMotion': 'SVGAnimateMotionElement', + 'animateTransform': 'SVGAnimateTransformElement', + 'circle': 'SVGCircleElement', + 'clipPath': 'SVGClipPathElement', + 'color-profile': 'SVGElement', + 'cursor': 'SVGCursorElement', + 'defs': 'SVGDefsElement', + 'desc': 'SVGDescElement', + 'discard': 'SVGDiscardElement', + 'ellipse': 'SVGEllipseElement', + 'feBlend': 'SVGFEBlendElement', + 'feColorMatrix': 'SVGFEColorMatrixElement', + 'feComponentTransfer': 'SVGFEComponentTransferElement', + 'feComposite': 'SVGFECompositeElement', + 'feConvolveMatrix': 'SVGFEConvolveMatrixElement', + 'feDiffuseLighting': 'SVGFEDiffuseLightingElement', + 'feDisplacementMap': 'SVGFEDisplacementMapElement', + 'feDistantLight': 'SVGFEDistantLightElement', + 'feDropShadow': 'SVGFEDropShadowElement', + 'feFlood': 'SVGFEFloodElement', + 'feFuncA': 'SVGFEFuncAElement', + 'feFuncB': 'SVGFEFuncBElement', + 'feFuncG': 'SVGFEFuncGElement', + 'feFuncR': 'SVGFEFuncRElement', + 'feGaussianBlur': 'SVGFEGaussianBlurElement', + 'feImage': 'SVGFEImageElement', + 'feMerge': 'SVGFEMergeElement', + 'feMergeNode': 'SVGFEMergeNodeElement', + 'feMorphology': 'SVGFEMorphologyElement', + 'feOffset': 'SVGFEOffsetElement', + 'fePointLight': 'SVGFEPointLightElement', + 'feSpecularLighting': 'SVGFESpecularLightingElement', + 'feSpotLight': 'SVGFESpotLightElement', + 'feTile': 'SVGFETileElement', + 'feTurbulence': 'SVGFETurbulenceElement', + 'filter': 'SVGFilterElement', + 'font': 'SVGElement', + 'font-face': 'SVGElement', + 'font-face-format': 'SVGElement', + 'font-face-name': 'SVGElement', + 'font-face-src': 'SVGElement', + 'font-face-uri': 'SVGElement', + 'foreignObject': 'SVGForeignObjectElement', + 'g': 'SVGGElement', + 'glyph': 'SVGElement', + 'glyphRef': 'SVGElement', + 'hatch': 'SVGElement', + 'hatchpath': 'SVGElement', + 'hkern': 'SVGElement', + 'image': 'SVGImageElement', + 'line': 'SVGLineElement', + 'linearGradient': 'SVGLinearGradientElement', + 'marker': 'SVGMarkerElement', + 'mask': 'SVGMaskElement', + 'mesh': 'SVGElement', + 'meshgradient': 'SVGElement', + 'meshpatch': 'SVGElement', + 'meshrow': 'SVGElement', + 'metadata': 'SVGMetadataElement', + 'missing-glyph': 'SVGElement', + 'mpath': 'SVGMPathElement', + 'path': 'SVGPathElement', + 'pattern': 'SVGPatternElement', + 'polygon': 'SVGPolygonElement', + 'polyline': 'SVGPolylineElement', + 'radialGradient': 'SVGRadialGradientElement', + 'rect': 'SVGRectElement', + 'set': 'SVGSetElement', + 'svg': 'SVGSVGElement', + 'solidcolor': 'SVGElement', + 'stop': 'SVGStopElement', + 'switch': 'SVGSwitchElement', + 'symbol': 'SVGSymbolElement', + 'text': 'SVGTextElement', + 'textPath': 'SVGTextPathElement', + 'title': 'SVGTitleElement', + 'tref': 'SVGElement', + 'tspan': 'SVGTSpanElement', + 'unknown': 'SVGElement', + 'use': 'SVGUseElement', + 'view': 'SVGViewElement', + 'vkern': 'SVGElement' +}