diff options
Diffstat (limited to 'meta-python/recipes-devtools')
2 files changed, 65 insertions, 0 deletions
diff --git a/meta-python/recipes-devtools/python/python3-sqlparse/0001-Optimize-regular-expression-for-identifying-line-bre.patch b/meta-python/recipes-devtools/python/python3-sqlparse/0001-Optimize-regular-expression-for-identifying-line-bre.patch new file mode 100644 index 0000000000..735530a8f4 --- /dev/null +++ b/meta-python/recipes-devtools/python/python3-sqlparse/0001-Optimize-regular-expression-for-identifying-line-bre.patch | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | From 8238a9e450ed1524e40cb3a8b0b3c00606903aeb Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Andi Albrecht <albrecht.andi@gmail.com> | ||
| 3 | Date: Tue, 7 Sep 2021 12:27:28 +0200 | ||
| 4 | Subject: [PATCH] Optimize regular expression for identifying line breaks in | ||
| 5 | comments. | ||
| 6 | |||
| 7 | CVE: CVE-2021-32839 | ||
| 8 | |||
| 9 | Upstream-Status: Backport | ||
| 10 | (https://github.com/andialbrecht/sqlparse/commit/8238a9e450ed1524e40cb3a8b0b3c00606903aeb) | ||
| 11 | |||
| 12 | Signed-off-by: Trevor Gamblin <trevor.gamblin@windriver.com> | ||
| 13 | --- | ||
| 14 | sqlparse/filters/others.py | 5 ++++- | ||
| 15 | tests/test_format.py | 17 +++++++++++++++++ | ||
| 16 | 2 files changed, 21 insertions(+), 1 deletion(-) | ||
| 17 | |||
| 18 | diff --git a/sqlparse/filters/others.py b/sqlparse/filters/others.py | ||
| 19 | index e0e1ca1..6905f2d 100644 | ||
| 20 | --- a/sqlparse/filters/others.py | ||
| 21 | +++ b/sqlparse/filters/others.py | ||
| 22 | @@ -22,7 +22,10 @@ class StripCommentsFilter: | ||
| 23 | def _get_insert_token(token): | ||
| 24 | """Returns either a whitespace or the line breaks from token.""" | ||
| 25 | # See issue484 why line breaks should be preserved. | ||
| 26 | - m = re.search(r'((\r\n|\r|\n)+) *$', token.value) | ||
| 27 | + # Note: The actual value for a line break is replaced by \n | ||
| 28 | + # in SerializerUnicode which will be executed in the | ||
| 29 | + # postprocessing state. | ||
| 30 | + m = re.search(r'((\r|\n)+) *$', token.value) | ||
| 31 | if m is not None: | ||
| 32 | return sql.Token(T.Whitespace.Newline, m.groups()[0]) | ||
| 33 | else: | ||
| 34 | diff --git a/tests/test_format.py b/tests/test_format.py | ||
| 35 | index 7117d9d..70bb805 100644 | ||
| 36 | --- a/tests/test_format.py | ||
| 37 | +++ b/tests/test_format.py | ||
| 38 | @@ -84,6 +84,23 @@ class TestFormat: | ||
| 39 | res = sqlparse.format(sql, strip_comments=True) | ||
| 40 | assert res == 'select (select 2)' | ||
| 41 | |||
| 42 | + def test_strip_comments_preserves_linebreak(self): | ||
| 43 | + sql = 'select * -- a comment\r\nfrom foo' | ||
| 44 | + res = sqlparse.format(sql, strip_comments=True) | ||
| 45 | + assert res == 'select *\nfrom foo' | ||
| 46 | + sql = 'select * -- a comment\nfrom foo' | ||
| 47 | + res = sqlparse.format(sql, strip_comments=True) | ||
| 48 | + assert res == 'select *\nfrom foo' | ||
| 49 | + sql = 'select * -- a comment\rfrom foo' | ||
| 50 | + res = sqlparse.format(sql, strip_comments=True) | ||
| 51 | + assert res == 'select *\nfrom foo' | ||
| 52 | + sql = 'select * -- a comment\r\n\r\nfrom foo' | ||
| 53 | + res = sqlparse.format(sql, strip_comments=True) | ||
| 54 | + assert res == 'select *\n\nfrom foo' | ||
| 55 | + sql = 'select * -- a comment\n\nfrom foo' | ||
| 56 | + res = sqlparse.format(sql, strip_comments=True) | ||
| 57 | + assert res == 'select *\n\nfrom foo' | ||
| 58 | + | ||
| 59 | def test_strip_ws(self): | ||
| 60 | f = lambda sql: sqlparse.format(sql, strip_whitespace=True) | ||
| 61 | s = 'select\n* from foo\n\twhere ( 1 = 2 )\n' | ||
| 62 | -- | ||
| 63 | 2.31.1 | ||
| 64 | |||
diff --git a/meta-python/recipes-devtools/python/python3-sqlparse_0.4.1.bb b/meta-python/recipes-devtools/python/python3-sqlparse_0.4.1.bb index c8a64c1095..aeb9c23505 100644 --- a/meta-python/recipes-devtools/python/python3-sqlparse_0.4.1.bb +++ b/meta-python/recipes-devtools/python/python3-sqlparse_0.4.1.bb | |||
| @@ -5,6 +5,7 @@ LICENSE = "BSD" | |||
| 5 | LIC_FILES_CHKSUM = "file://LICENSE;md5=2b136f573f5386001ea3b7b9016222fc" | 5 | LIC_FILES_CHKSUM = "file://LICENSE;md5=2b136f573f5386001ea3b7b9016222fc" |
| 6 | 6 | ||
| 7 | SRC_URI += "file://0001-sqlparse-change-shebang-to-python3.patch \ | 7 | SRC_URI += "file://0001-sqlparse-change-shebang-to-python3.patch \ |
| 8 | file://0001-Optimize-regular-expression-for-identifying-line-bre.patch \ | ||
| 8 | file://run-ptest \ | 9 | file://run-ptest \ |
| 9 | " | 10 | " |
| 10 | 11 | ||
