PabloRMira / sql_formatter

A Python based SQL formatter
https://pablormira.github.io/sql_formatter/
Apache License 2.0
43 stars 10 forks source link

comment assignment fails sometimes #129

Closed PabloRMira closed 3 years ago

PabloRMira commented 3 years ago

To Reproduce

assert_and_print(
    format_select("select asdf, -- Some comment[C]antworqwer -- Another comment[C]"),
"""
select asdf, -- Some comment
       antworqwert -- Another comment
""".strip()
)
PabloRMira commented 3 years ago

This was because of regex in sql_formatter.utils.assign_comment() function.

The regex for (?:and|or) needed a boundary character \b at beginning and end. Otherwise (as in the example above) it replaces and / or within a word