Skip to content

Commit

Permalink
Escape double quotes and backslashes in ssid and psk (esphome#507)
Browse files Browse the repository at this point in the history
## Description:
Escape ssid and psk

**Related issue (if applicable):** fixes <link to issue>
esphome/issues#81

**Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here>
**Pull request in [esphome-core](https://github.com/esphome/esphome-core) with C++ framework changes (if applicable):** esphome/esphome-core#<esphome-core PR number goes here>

## 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 <[email protected]>
  • Loading branch information
gitolicious and OttoWinter committed Apr 15, 2019
1 parent 336f12b commit 049807e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion esphome/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@
"""


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"

Expand All @@ -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']
Expand Down

0 comments on commit 049807e

Please sign in to comment.