Skip to content

Commit

Permalink
[DSW-2102] fix(tdk): Fix TDK when creating template with brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Oct 6, 2023
1 parent f436799 commit bb25fe0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/dsw-tdk/dsw/tdk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .core import TDKCore, TDKProcessingError
from .consts import VERSION, DEFAULT_LIST_FORMAT
from .model import Template
from .utils import TemplateBuilder, FormatSpec
from .utils import TemplateBuilder, FormatSpec, safe_utf8
from .validation import ValidationError

CURRENT_DIR = pathlib.Path.cwd()
Expand Down Expand Up @@ -72,7 +72,8 @@ def watch_change(cls, change_type: watchfiles.Change, filepath: pathlib.Path, ro
def prompt_fill(text: str, obj, attr, **kwargs):
while True:
try:
setattr(obj, attr, click.prompt(text, **kwargs).strip())
value = safe_utf8(click.prompt(text, **kwargs).strip())
setattr(obj, attr, value)
break
except ValidationError as e:
ClickPrinter.error(e.message)
Expand Down
4 changes: 4 additions & 0 deletions packages/dsw-tdk/dsw/tdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,7 @@ def build(self) -> Template:

def create_dot_env(api_url: Optional[str] = None, api_key: Optional[str] = None) -> str:
return j2_env.get_template('env.j2').render(api_url=api_url, api_key=api_key)


def safe_utf8(text: str) -> str:
return text.encode(encoding='utf-8', errors='ignore').decode(encoding='utf-8')

0 comments on commit bb25fe0

Please sign in to comment.