summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Stark <jhnstrk@gmail.com>2023-01-05 20:40:13 +0100
committerJohn Stark <jhnstrk@gmail.com>2023-01-05 20:40:13 +0100
commit0db66d2aa3c5abe79e55017435894898a2ebe898 (patch)
treee33e6d7bb7eb448302b3299545657203caf371f0
parent45111ba0b67e8619265d89f3202635e62c13cde6 (diff)
downloadruamel.yaml-449_secondary_tag_url_enc.tar.gz
Fix secondary tag encoding. See #449449_secondary_tag_url_enc
The second exclamation mark was getting url encoded, when it should be preserved. Added a regression test.
-rw-r--r--_test/test_issues.py6
-rw-r--r--_test/test_tag.py9
-rw-r--r--emitter.py3
-rw-r--r--scanner.py13
4 files changed, 27 insertions, 4 deletions
diff --git a/_test/test_issues.py b/_test/test_issues.py
index 736dccb..dce77e5 100644
--- a/_test/test_issues.py
+++ b/_test/test_issues.py
@@ -862,6 +862,12 @@ class TestIssues:
"""
d = na_round_trip(inp) # NOQA
+ def test_issue_449(self):
+ inp = """\
+ emoji_index: !!python/name:materialx.emoji.twemoji
+ """
+ d = na_round_trip(inp) # NOQA
+
# @pytest.mark.xfail(strict=True, reason='bla bla', raises=AssertionError)
# def test_issue_ xxx(self):
# inp = """
diff --git a/_test/test_tag.py b/_test/test_tag.py
index 3fd1e05..ec086f3 100644
--- a/_test/test_tag.py
+++ b/_test/test_tag.py
@@ -64,6 +64,15 @@ class TestIndentFailures:
language: python
""")
+ def test_spec_6_26_tag_shorthands(self):
+ round_trip("""\
+ %TAG !e! tag:example.com,2000:app/
+ ---
+ - !local foo
+ - !!str bar
+ - !e!tag%21 baz
+ """)
+
class TestRoundTripCustom:
def test_X1(self):
diff --git a/emitter.py b/emitter.py
index f9611ee..2a0d3ca 100644
--- a/emitter.py
+++ b/emitter.py
@@ -97,6 +97,7 @@ class Emitter:
DEFAULT_TAG_PREFIXES = {
'!': '!',
'tag:yaml.org,2002:': '!!',
+ '!!': '!!',
}
# fmt: on
@@ -1012,7 +1013,7 @@ class Emitter:
# type: (Any) -> Any
if not tag:
raise EmitterError('tag must not be empty')
- if tag == '!':
+ if tag == '!' or tag == '!!':
return tag
handle = None
suffix = tag
diff --git a/scanner.py b/scanner.py
index 61cae63..86f7caf 100644
--- a/scanner.py
+++ b/scanner.py
@@ -1098,6 +1098,13 @@ class Scanner:
srp = self.reader.peek
start_mark = self.reader.get_mark()
ch = srp(1)
+ short_handle = '!'
+ if ch == '!':
+ short_handle = '!!'
+ self.reader.forward()
+ srp = self.reader.peek
+ ch = srp(1)
+
if ch == '<':
handle = None
self.reader.forward(2)
@@ -1112,7 +1119,7 @@ class Scanner:
self.reader.forward()
elif ch in _THE_END_SPACE_TAB:
handle = None
- suffix = '!'
+ suffix = short_handle
self.reader.forward()
else:
length = 1
@@ -1123,11 +1130,11 @@ class Scanner:
break
length += 1
ch = srp(length)
- handle = '!'
+ handle = short_handle
if use_handle:
handle = self.scan_tag_handle('tag', start_mark)
else:
- handle = '!'
+ handle = short_handle
self.reader.forward()
suffix = self.scan_tag_uri('tag', start_mark)
ch = srp()