Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

project_loader: handle invalid unicode chars #1941

Merged
merged 6 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions snapcraft/internal/project_loader/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ def _snapcraft_yaml_load(yaml_file):
except yaml.scanner.ScannerError as e:
raise errors.YamlValidationError('{} on line {} of {}'.format(
e.problem, e.problem_mark.line + 1, yaml_file)) from e
except yaml.reader.ReaderError as e:
raise errors.YamlValidationError(
'Invalid character {!r} at position {} of {}: {}'.format(
chr(e.character), e.position + 1, yaml_file, e.reason)) from e


def _ensure_confinement_default(yaml_data, schema):
Expand Down
17 changes: 17 additions & 0 deletions snapcraft/tests/unit/project_loader/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,23 @@ def test_invalid_yaml_missing_icon(self):
self.assertThat(raised.message,
Equals("Specified icon 'icon.png' does not exist"))

def test_invalid_yaml_invalid_unicode_chars(self):
fake_logger = fixtures.FakeLogger(level=logging.ERROR)
self.useFixture(fake_logger)

self.make_snapcraft_yaml("""name: foobar
version: "1"
summary: test馃挬
description: nothing
""")
raised = self.assertRaises(
errors.YamlValidationError,
_config.Config)

self.assertThat(raised.message, Equals(
"Invalid character '馃挬' at position 40 "
"of snap/snapcraft.yaml: special characters are not allowed"))

def test_invalid_yaml_invalid_name_chars(self):
fake_logger = fixtures.FakeLogger(level=logging.ERROR)
self.useFixture(fake_logger)
Expand Down