From 049807e3ab2d923b0c8b3f2acb4ca033ef38f2ab Mon Sep 17 00:00:00 2001 From: gitolicious Date: Mon, 15 Apr 2019 21:49:21 +0200 Subject: [PATCH] Escape double quotes and backslashes in ssid and psk (#507) ## Description: Escape ssid and psk **Related issue (if applicable):** fixes https://github.com/esphome/issues/issues/81 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs# **Pull request in [esphome-core](https://github.com/esphome/esphome-core) with C++ framework changes (if applicable):** esphome/esphome-core# ## Checklist: - [X] The code change is tested and works locally. - [n/a] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [n/a] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs). Co-authored-by: Otto Winter --- esphome/wizard.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/esphome/wizard.py b/esphome/wizard.py index abc2270235..091e364acd 100644 --- a/esphome/wizard.py +++ b/esphome/wizard.py @@ -61,11 +61,15 @@ api: """ +def sanitize_double_quotes(value): + return value.replace('\\', '\\\\').replace('"', '\\"') + + def wizard_file(**kwargs): config = BASE_CONFIG.format(**kwargs) if kwargs['password']: - config += u" password: '{0}'\n\nota:\n password: '{0}'\n".format(kwargs['password']) + config += u' password: "{0}"\n\nota:\n password: "{0}"\n'.format(kwargs['password']) else: config += u"\nota:\n" @@ -75,6 +79,11 @@ def wizard_file(**kwargs): def wizard_write(path, **kwargs): name = kwargs['name'] board = kwargs['board'] + + kwargs['ssid'] = sanitize_double_quotes(kwargs['ssid']) + kwargs['psk'] = sanitize_double_quotes(kwargs['psk']) + kwargs['password'] = sanitize_double_quotes(kwargs['password']) + if 'platform' not in kwargs: kwargs['platform'] = 'ESP8266' if board in ESP8266_BOARD_PINS else 'ESP32' platform = kwargs['platform']