From 845c361de702481172dbf962dcbb6f7e20e7a733 Mon Sep 17 00:00:00 2001 From: Ted Conbeer Date: Tue, 6 Jun 2023 03:28:07 -0600 Subject: [PATCH] fix #434: improve comment safety check --- CHANGELOG.md | 4 ++++ src/sqlfmt/api.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b45c8fe..abc39be0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ All notable changes to this project will be documented in this file. - Relative `exclude` paths defined in `pyproject.toml` files are now evaluated relative to the location of the file, not the current working directory. Relative paths provided to the `--exclude` option (or env var) are evaluated relative to the current working directory. Files and exclude paths are now compared as resolved, absolute paths. (Fixes [#431](https://github.com/tconbeer/sqlfmt/issues/431) - thank you [@cmcnicoll](https://github.com/cmcnicoll)!) +- Fixes a bug where a comment like `{#-- comment --#}` would cause a false positive for the + comment safety check. ([#434](https://github.com/tconbeer/sqlfmt/issues/434)) + +### Formatting Changes - sqlfmt now supports the `<=>` operator ([#432](https://github.com/tconbeer/sqlfmt/issues/432) - thank you [@kathykwon](https://github.com/kathykwon)!) ## [0.18.3] - 2023-05-31 diff --git a/src/sqlfmt/api.py b/src/sqlfmt/api.py index f73cd52b..33048aba 100755 --- a/src/sqlfmt/api.py +++ b/src/sqlfmt/api.py @@ -371,10 +371,10 @@ def _perform_safety_check(analyzer: Analyzer, raw_query: Query, result: str) -> comment.token.token for line in result_query.lines for comment in line.comments ] stripped_raw = "".join( - ["".join(c.replace("--", "").replace("#", "").split()) for c in raw_comments] + ["".join(c.split()).replace("--", "").replace("#", "") for c in raw_comments] ) stripped_res = "".join( - ["".join(c.replace("--", "").replace("#", "").split()) for c in result_comments] + ["".join(c.split()).replace("--", "").replace("#", "") for c in result_comments] ) try: assert stripped_raw == stripped_res