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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make style=... consistent for unquoted scalar tokens #836

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yaml/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ def scan_plain(self):
if not spaces or self.peek() == '#' \
or (not self.flow_level and self.column < indent):
break
return ScalarToken(''.join(chunks), True, start_mark, end_mark)
return ScalarToken(''.join(chunks), True, start_mark, end_mark, style='')

def scan_plain_spaces(self, indent, start_mark):
# See the specification for details.
Expand Down
18 changes: 18 additions & 0 deletions tests/test_scan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

import yaml
from yaml.tokens import StreamStartToken, ScalarToken, StreamEndToken


_loaders = (yaml.SafeLoader,)
if yaml.__with_libyaml__:
_loaders += (yaml.CSafeLoader,)


@pytest.mark.parametrize('loader_cls', _loaders)
def test_scan_produces_empty_string_style_for_scalar_node(loader_cls):
start, scalar, end = yaml.scan('example', Loader=loader_cls)
assert isinstance(start, StreamStartToken)
assert isinstance(scalar, ScalarToken)
assert scalar.style == ''
assert isinstance(end, StreamEndToken)
Loading