|
| 1 | +import re |
| 2 | + |
| 3 | +# linear |
| 4 | +# https://github.com/github/codeql-python-CVE-coverage/issues/439 |
| 5 | +rex_blame = re.compile(r'\s*(\d+)\s*(\S+) (.*)') |
| 6 | + |
| 7 | +# https://github.com/github/codeql-python-CVE-coverage/issues/402 |
| 8 | +whitespace = br"[\000\011\012\014\015\040]" |
| 9 | +whitespace_optional = whitespace + b"*" |
| 10 | +newline_only = br"[\r\n]+" |
| 11 | +newline = whitespace_optional + newline_only + whitespace_optional |
| 12 | +toFlag = re.compile(newline) |
| 13 | + |
| 14 | +# https://github.com/github/codeql-python-CVE-coverage/issues/400 |
| 15 | +re.compile(r'[+-]?(\d+)*\.\d+%?') |
| 16 | +re.compile(r'"""\s+(?:.|\n)*?\s+"""') |
| 17 | +re.compile(r'(\{\s+)(\S+)(\s+[^}]+\s+\}\s)') |
| 18 | +re.compile(r'".*``.*``.*"') |
| 19 | +re.compile(r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)') |
| 20 | +re.compile(r'(%config)(\s*\(\s*)(\w+)(\s*=\s*)(.*?)(\s*\)\s*)') |
| 21 | +re.compile(r'(%new)(\s*)(\()(\s*.*?\s*)(\))') |
| 22 | +re.compile(r'(\$)(evoque|overlay)(\{(%)?)(\s*[#\w\-"\'.]+[^=,%}]+?)?') |
| 23 | +re.compile(r'(\.\w+\b)(\s*=\s*)([^;]*)(\s*;)') |
| 24 | + |
| 25 | +# linear |
| 26 | +# https://github.com/github/codeql-python-CVE-coverage/issues/392 |
| 27 | +simple_email_re = re.compile(r"^\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+$") |
| 28 | + |
| 29 | +# https://github.com/github/codeql-python-CVE-coverage/issues/249 |
| 30 | +rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+' |
| 31 | + 'realm=(["\']?)([^"\']*)\\2', re.I) |
| 32 | + |
| 33 | +# https://github.com/github/codeql-python-CVE-coverage/issues/248 |
| 34 | +gauntlet = re.compile( |
| 35 | + r"""^([-/:,#%.'"\s!\w]|\w-\w|'[\s\w]+'\s*|"[\s\w]+"|\([\d,%\.\s]+\))*$""", |
| 36 | + flags=re.U |
| 37 | + ) |
| 38 | + |
| 39 | +# https://github.com/github/codeql-python-CVE-coverage/issues/227 |
| 40 | +# from .compat import tobytes |
| 41 | + |
| 42 | +WS = "[ \t]" |
| 43 | +OWS = WS + "{0,}?" |
| 44 | + |
| 45 | +# RFC 7230 Section 3.2.6 "Field Value Components": |
| 46 | +# tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" |
| 47 | +# / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" |
| 48 | +# / DIGIT / ALPHA |
| 49 | +# obs-text = %x80-FF |
| 50 | +TCHAR = r"[!#$%&'*+\-.^_`|~0-9A-Za-z]" |
| 51 | +OBS_TEXT = r"\x80-\xff" |
| 52 | +TOKEN = TCHAR + "{1,}" |
| 53 | +# RFC 5234 Appendix B.1 "Core Rules": |
| 54 | +# VCHAR = %x21-7E |
| 55 | +# ; visible (printing) characters |
| 56 | +VCHAR = r"\x21-\x7e" |
| 57 | +# header-field = field-name ":" OWS field-value OWS |
| 58 | +# field-name = token |
| 59 | +# field-value = *( field-content / obs-fold ) |
| 60 | +# field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] |
| 61 | +# field-vchar = VCHAR / obs-text |
| 62 | +# Errata from: https://www.rfc-editor.org/errata_search.php?rfc=7230&eid=4189 |
| 63 | +# changes field-content to: |
| 64 | +# |
| 65 | +# field-content = field-vchar [ 1*( SP / HTAB / field-vchar ) |
| 66 | +# field-vchar ] |
| 67 | + |
| 68 | +FIELD_VCHAR = "[" + VCHAR + OBS_TEXT + "]" |
| 69 | +FIELD_CONTENT = FIELD_VCHAR + "([ \t" + VCHAR + OBS_TEXT + "]+" + FIELD_VCHAR + "){,1}" |
| 70 | +FIELD_VALUE = "(" + FIELD_CONTENT + "){0,}" |
| 71 | + |
| 72 | +HEADER_FIELD = re.compile( |
| 73 | + # tobytes( |
| 74 | + "^(?P<name>" + TOKEN + "):" + OWS + "(?P<value>" + FIELD_VALUE + ")" + OWS + "$" |
| 75 | + # ) |
| 76 | + ) |
| 77 | + |
| 78 | +# https://github.com/github/codeql-python-CVE-coverage/issues/224 |
| 79 | +pattern = re.compile( |
| 80 | + r'^(:?(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|' # domain pt.1 |
| 81 | + r'([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|' # domain pt.2 |
| 82 | + r'([a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]))\.)+' # domain pt.3 |
| 83 | + r'([a-zA-Z]{2,13}|(xn--[a-zA-Z0-9]{2,30}))$' # TLD |
| 84 | +) |
| 85 | + |
| 86 | +# https://github.com/github/codeql-python-CVE-coverage/issues/189 |
| 87 | +URL_REGEX = ( |
| 88 | + r'(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|' |
| 89 | + r'[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|' |
| 90 | + r'(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|' |
| 91 | + r'[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))' # "emacs! |
| 92 | +) |
| 93 | + |
| 94 | +url = re.compile(URL_REGEX) |
0 commit comments