Download tasks/codeql_python_benchmark51_v2/pyvul-509b1de3e2277ac89469/patch.diff from Benchanything/checkerbench: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-509b1de3e2277ac89469/patch.diff
- Command line
-
hf download hf://datasets/Benchanything/checkerbench/tasks/codeql_python_benchmark51_v2/pyvul-509b1de3e2277ac89469/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-509b1de3e2277ac89469/patch.diff
2.07 kB
| diff --git a/sqlparse/filters/others.py b/sqlparse/filters/others.py | |
| index e0e1ca1..6905f2d 100644 | |
| --- a/sqlparse/filters/others.py | |
| +++ b/sqlparse/filters/others.py | |
| class StripCommentsFilter: | |
| def _get_insert_token(token): | |
| """Returns either a whitespace or the line breaks from token.""" | |
| # See issue484 why line breaks should be preserved. | |
| - m = re.search(r'((\r\n|\r|\n)+) *$', token.value) | |
| + # Note: The actual value for a line break is replaced by \n | |
| + # in SerializerUnicode which will be executed in the | |
| + # postprocessing state. | |
| + m = re.search(r'((\r|\n)+) *$', token.value) | |
| if m is not None: | |
| return sql.Token(T.Whitespace.Newline, m.groups()[0]) | |
| else: | |
| diff --git a/tests/test_format.py b/tests/test_format.py | |
| index 7117d9d..70bb805 100644 | |
| --- a/tests/test_format.py | |
| +++ b/tests/test_format.py | |
| class TestFormat: | |
| res = sqlparse.format(sql, strip_comments=True) | |
| assert res == 'select (select 2)' | |
| + def test_strip_comments_preserves_linebreak(self): | |
| + sql = 'select * -- a comment\r\nfrom foo' | |
| + res = sqlparse.format(sql, strip_comments=True) | |
| + assert res == 'select *\nfrom foo' | |
| + sql = 'select * -- a comment\nfrom foo' | |
| + res = sqlparse.format(sql, strip_comments=True) | |
| + assert res == 'select *\nfrom foo' | |
| + sql = 'select * -- a comment\rfrom foo' | |
| + res = sqlparse.format(sql, strip_comments=True) | |
| + assert res == 'select *\nfrom foo' | |
| + sql = 'select * -- a comment\r\n\r\nfrom foo' | |
| + res = sqlparse.format(sql, strip_comments=True) | |
| + assert res == 'select *\n\nfrom foo' | |
| + sql = 'select * -- a comment\n\nfrom foo' | |
| + res = sqlparse.format(sql, strip_comments=True) | |
| + assert res == 'select *\n\nfrom foo' | |
| + | |
| def test_strip_ws(self): | |
| f = lambda sql: sqlparse.format(sql, strip_whitespace=True) | |
| s = 'select\n* from foo\n\twhere ( 1 = 2 )\n' | |