Skip to content

fix(mssql): escape special characters in passwords #10437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ibis/backends/mssql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,17 @@ def do_connect(
self.con = pyodbc.connect(
user=user,
server=f"{host},{port}",
password=password,
password=self._escape_special_characters(password),
driver=driver,
**kwargs,
)

self._post_connect()

@staticmethod
def _escape_special_characters(value: str) -> str:
return "{" + value.replace("}", "}}") + "}"

@util.experimental
@classmethod
def from_connection(cls, con: pyodbc.Connection) -> Backend:
Expand Down
11 changes: 11 additions & 0 deletions ibis/backends/mssql/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,14 @@ def test_create_temp_table(con, temp):
assert t.columns == ("a",)
finally:
con.drop_table(name)


def test_escape_special_characters():
test_func = ibis.backends.mssql.Backend._escape_special_characters
assert test_func("1bis_Testing!") == "{1bis_Testing!}"
assert test_func("{1bis_Testing!") == "{{1bis_Testing!}"
assert test_func("1bis_Testing!}") == "{1bis_Testing!}}}"
assert test_func("{1bis_Testing!}") == "{{1bis_Testing!}}}"
assert test_func("1bis}Testing!") == "{1bis}}Testing!}"
assert test_func("{R;3G1/8Al2AniRye") == "{{R;3G1/8Al2AniRye}"
assert test_func("{R;3G1/8Al2AniRye}") == "{{R;3G1/8Al2AniRye}}}"
Loading