Allow emoji in config file in Windows by always opening it as unicode (#1313)

* Open config file as utf-8 always
* Add test for journal with emoji name
This commit is contained in:
Micah Jerome Ellison 2021-08-21 14:43:11 -07:00 committed by GitHub
parent 7109374d42
commit 050c17ee06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View file

@ -20,6 +20,7 @@ DEFAULT_JOURNAL_NAME = "journal.txt"
DEFAULT_JOURNAL_KEY = "default"
YAML_SEPARATOR = ": "
YAML_FILE_ENCODING = "utf-8"
def make_yaml_valid_dict(input: list) -> dict:
@ -48,9 +49,13 @@ def make_yaml_valid_dict(input: list) -> dict:
def save_config(config):
config["version"] = __version__
with open(get_config_path(), "w") as f:
with open(get_config_path(), "w", encoding=YAML_FILE_ENCODING) as f:
yaml.safe_dump(
config, f, encoding="utf-8", allow_unicode=True, default_flow_style=False
config,
f,
encoding=YAML_FILE_ENCODING,
allow_unicode=True,
default_flow_style=False,
)
@ -139,7 +144,7 @@ def verify_config_colors(config):
def load_config(config_path):
"""Tries to load a config file from YAML."""
with open(config_path) as f:
with open(config_path, encoding=YAML_FILE_ENCODING) as f:
return yaml.load(f, Loader=yaml.SafeLoader)

View file

@ -88,3 +88,9 @@ Feature: Multiple journals
these three eyes
n
Then the output should contain "Encrypted journal 'new_encrypted' created"
Scenario: Read and write to journal with emoji name
Given we use the config "multiple.yaml"
When we run "jrnl Adding entry to sparkly journal"
When we run "jrnl -1"
Then the output should contain "Adding entry to sparkly journal"

View file

@ -12,6 +12,7 @@ journals:
new_encrypted:
encrypt: true
journal: features/journals/new_encrypted.journal
: features/journals/simple.journal
linewrap: 80
tagsymbols: '@'
timeformat: '%Y-%m-%d %H:%M'