Fixed a problem when CDumper incorrectly serializes a node anchor.
diff --git a/ext/_yaml.pyx b/ext/_yaml.pyx
index ab17623..3be0f4f 100644
--- a/ext/_yaml.pyx
+++ b/ext/_yaml.pyx
@@ -1380,7 +1380,14 @@
anchor_object = self.anchors[node]
anchor = NULL
if anchor_object is not None:
- anchor = PyString_AS_STRING(PyUnicode_AsUTF8String(anchor_object))
+ if PyUnicode_CheckExact(anchor_object):
+ anchor_object = PyUnicode_AsUTF8String(anchor_object)
+ if not PyString_CheckExact(anchor_object):
+ if PY_MAJOR_VERSION < 3:
+ raise TypeError("anchor must be a string")
+ else:
+ raise TypeError(u"anchor must be a string")
+ anchor = PyString_AS_STRING(anchor_object)
if node in self.serialized_nodes:
if yaml_alias_event_initialize(&event, anchor) == 0:
raise MemoryError
diff --git a/tests/data/aliases-cdumper-bug.code b/tests/data/aliases-cdumper-bug.code
new file mode 100644
index 0000000..0168441
--- /dev/null
+++ b/tests/data/aliases-cdumper-bug.code
@@ -0,0 +1 @@
+[ today, today ]
diff --git a/tests/lib/test_constructor.py b/tests/lib/test_constructor.py
index 0aacf17..beee7b0 100644
--- a/tests/lib/test_constructor.py
+++ b/tests/lib/test_constructor.py
@@ -17,7 +17,7 @@
global MyLoader, MyDumper, MyTestClass1, MyTestClass2, MyTestClass3, YAMLObject1, YAMLObject2, \
AnObject, AnInstance, AState, ACustomState, InitArgs, InitArgsWithState, \
NewArgs, NewArgsWithState, Reduce, ReduceWithState, MyInt, MyList, MyDict, \
- FixedOffset, execute
+ FixedOffset, today, execute
class MyLoader(yaml.Loader):
pass
@@ -213,6 +213,8 @@
def dst(self, dt):
return datetime.timedelta(0)
+ today = datetime.date.today()
+
def _load_code(expression):
return eval(expression)
diff --git a/tests/lib3/test_constructor.py b/tests/lib3/test_constructor.py
index b4b0884..427f53c 100644
--- a/tests/lib3/test_constructor.py
+++ b/tests/lib3/test_constructor.py
@@ -14,7 +14,7 @@
global MyLoader, MyDumper, MyTestClass1, MyTestClass2, MyTestClass3, YAMLObject1, YAMLObject2, \
AnObject, AnInstance, AState, ACustomState, InitArgs, InitArgsWithState, \
NewArgs, NewArgsWithState, Reduce, ReduceWithState, MyInt, MyList, MyDict, \
- FixedOffset, execute
+ FixedOffset, today, execute
class MyLoader(yaml.Loader):
pass
@@ -200,6 +200,8 @@
def dst(self, dt):
return datetime.timedelta(0)
+ today = datetime.date.today()
+
def _load_code(expression):
return eval(expression)