Skip to content

Commit

Permalink
make style=... consistent for unquoted scalar tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Oct 8, 2024
1 parent 69c141a commit 008648f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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)

0 comments on commit 008648f

Please sign in to comment.