Commit Graph

74 Commits

Author SHA1 Message Date
Tina Müller
07c88c6c1b Allow to turn off sorting keys in Dumper 2019-03-08 09:09:48 -08:00
Tina Müller
857dff153d Apply FullLoader/UnsafeLoader changes to lib3 2019-03-08 09:09:48 -08:00
Ingy döt Net
0cedb2a069 Deprecate/warn usage of yaml.load(input)
The `load` and `load_all` methods will issue a warning when they are
called without the 'Loader=' parameter. The warning will point to a URL
that is always up to date with the latest information on the usage of
`load`.

There are several ways to stop the warning:

* Use `full_load(input)` - sugar for `yaml.load(input, FullLoader)`
  * FullLoader is the new safe but complete loader class
* Use `safe_load(input)` - sugar for `yaml.load(input, SafeLoader)`
  * Make sure your input YAML consists of the 'safe' subset
* Use `unsafe_load(input)` - sugar for `yaml.load(input, UnsafeLoader)`
  * Make sure your input YAML consists of the 'safe' subset
* Use `yaml.load(input, Loader=yaml.<loader>)`
  * Or shorter `yaml.load(input, yaml.<loader>)`
  * Where '<loader>' can be:
    * FullLoader - safe, complete Python YAML loading
    * SafeLoader - safe, partial Python YAML loading
    * UnsafeLoader - more explicit name for the old, unsafe 'Loader' class
* yaml.warnings({'YAMLLoadWarning': False})
  * Use this when you use third party modules that use `yaml.load(input)`
  * Only do this if input is trusted

The above `load()` expressions all have `load_all()` counterparts.

You can get the original unsafe behavior with:
* `yaml.unsafe_load(input)`
* `yaml.load(input, Loader=yaml.UnsafeLoader)`

In a future release, `yaml.load(input)` will raise an exception.

The new loader called FullLoader is almost entirely complete as
Loader/UnsafeLoader but it does it avoids all known code execution
paths. It is the preferred YAML loader, and the current default for
`yaml.load(input)` when you get the warning.

Here are some of the exploits that can be triggered with UnsafeLoader
but not with FullLoader:
```
python -c 'import os, yaml; yaml.full_load("!!python/object/new:os.system [echo EXPLOIT!]")'`
python -c 'import yaml; print yaml.full_load("!!python/object/new:abs [-5]")'
python -c 'import yaml; yaml.full_load("!!python/object/new:eval [exit(5)]")' ; echo $?
python -c 'import yaml; yaml.full_load("!!python/object/new:exit [5]")' ; echo $?
2019-03-08 09:09:48 -08:00
Ingy döt Net
ccc40f3e2b Reverting https://github.com/yaml/pyyaml/pull/74
Revert "Make pyyaml safe by default."

This reverts commit bbcf95fa05.
This reverts commit 7b68405c81.
This reverts commit 517e83e805.
2018-06-30 15:46:56 -07:00
Alex Gaynor
bbcf95fa05 Now, for py3k! 2017-08-26 10:26:01 -05:00
Alex Gaynor
7b68405c81 Make pyyaml safe by default.
Change yaml.load/yaml.dump to be yaml.safe_load/yaml.safe_dump, introduced yaml.danger_dump/yaml.danger_load, and the same for various other classes.

(python2 only at this moment)

Refs #5
2017-08-26 10:26:01 -05:00
Peter Murphy
c67d8df8e4 Suspicious 'expected an exception' messages trimmed 2017-05-10 07:53:42 +10:00
Peter Murphy
c60232d69a Added emoticon test data files (which will probably break testing) 2017-05-09 23:07:36 +10:00
Daniel Beer
c5b135fe39 Allow colon in a plain scalar in a flow context (#45)
* Allow colon in a plain scalar in a flow context

* Restore behavior of flow mapping with empty value
2017-02-08 13:50:53 -06:00
Kirill Simonov
eb9932ac1c Fixed handling --verbose flag in the test appliance. 2016-08-25 22:24:45 -05:00
Kirill Simonov
7eeba34467 removed a test which fails when wheel is imported. 2016-06-16 23:01:38 -05:00
Kirill Simonov
491508b042 Raise an error when test suite failed. 2016-06-15 20:28:10 -05:00
Kirill Simonov
7e1b5fae0b Clear cyclic references in the parser and the emitter to avoid extra GC calls. 2011-05-30 02:51:30 +00:00
Kirill Simonov
1626bb30f5 Fixed tests on the Windows platform. 2009-08-31 09:09:21 +00:00
Kirill Simonov
3889e354cf Fixed another encoding issue. 2009-08-31 08:47:05 +00:00
Kirill Simonov
335c34455d Fixed a problem with a scanner error not detected when no line break at the end of the stream. 2009-08-29 22:12:45 +00:00
Kirill Simonov
fa14e18b38 Fixed emitting of invalid BOM for UTF-16. 2009-08-29 20:59:56 +00:00
Kirill Simonov
706e36ab64 Fixed a problem when CDumper incorrectly serializes a node anchor. 2009-08-29 19:15:31 +00:00
Kirill Simonov
6a62e8e7e0 Final touches before the release. 2008-12-30 18:18:53 +00:00
Kirill Simonov
e2bf4f3a03 Minor compatibility fixes. 2008-12-30 14:55:47 +00:00
Kirill Simonov
bf272b0339 Fixed str/bytes issues with Python 3 in _yaml.pyx. 2008-12-30 13:30:52 +00:00
Kirill Simonov
5f5e9a9494 Handle the encoding of input and output streams in a uniform way. 2008-12-30 04:02:04 +00:00
Kirill Simonov
7d5f9450cf Use Cython if available; added Python 3 support to _yaml.pyx. 2008-12-29 23:21:43 +00:00
Kirill Simonov
ab8d940469 Share data files between Py2 and Py3 test suites. 2008-12-29 19:05:11 +00:00
Kirill Simonov
8e88d11b41 Minor 2.3 and win32 compatibility fixes; clarify the 'feature not found' message in setup.py. 2008-12-28 21:42:35 +00:00
Kirill Simonov
1e842301f4 Fixed an issue with ReaderError generated by the LibYAML wrapper. 2008-12-28 20:41:41 +00:00
Kirill Simonov
aff84ff195 Refactored the test suite; updated include and library paths in setup.cfg. 2008-12-28 20:16:50 +00:00
Kirill Simonov
93f64d3c79 Fixed test errors for LibYAML bindings; added a test on emitting nodes in all possible styles. 2008-12-27 19:09:03 +00:00
Kirill Simonov
7baeadf46f Minor fixes in the test subsystem to prevent failures in LibYAML bindings tests. 2008-12-27 14:54:07 +00:00
Kirill Simonov
4692b60d88 Added the script tests/test_all.py. 2008-10-01 23:16:55 +00:00
Kirill Simonov
3ded20780b Added a test for single dot being a float bug. 2008-09-30 11:56:14 +00:00
Kirill Simonov
073f08e9d9 A single dot is not a float value (fixes #62). 2007-11-18 00:47:32 +00:00
Kirill Simonov
046f114050 Make compose() and load() ensure that the input stream contains a single document. Fixes #54. 2007-08-21 20:25:34 +00:00
Kirill Simonov
e5059a1d53 Add the tests for checking the libyaml bug. 2007-03-22 16:12:36 +00:00
Kirill Simonov
ed79023a71 Fix loss of microsecond precision in datetime.datetime constructor (fix #30).
Thanks to edemaine@mit.edu for the bug report and the patch.
2006-10-04 07:42:50 +00:00
Kirill Simonov
cc9c738342 Fix loading an empty YAML stream. 2006-09-12 13:53:30 +00:00
Kirill Simonov
b4643e77c3 Fix a test to work under Python 2.3. 2006-08-20 09:10:47 +00:00
Kirill Simonov
8f9b8bed40 The 'N' plain scalar was still recognized as `!!bool`. Fix it (close #26). 2006-08-16 21:07:47 +00:00
Kirill Simonov
29413ea88e Fix timestamp constructing and representing (close #25). 2006-08-16 18:22:38 +00:00
Kirill Simonov
17fa129ada Completely rewrite the libyaml bindings. 2006-08-13 13:46:20 +00:00
Kirill Simonov
8b083c6a96 Subclass all base classes from object.
Hold references to the objects being represented (should fix #22).

The value of a mapping node is represented as a list of pairs `(key, value)`
now.

Sort dictionary items (fix #23).

Recursive structures are now loaded and dumped correctly, including complex
structures like recursive tuples (fix #5). Thanks Peter Murphy for the patches.
To make it possible, representer functions are allowed to be generators.
In this case, the first generated value is an object. Other values produced
by the representer are ignored.

Make Representer not try to guess `!!pairs` when a list is represented.
You need to construct a `!!pairs` node explicitly now.

Do not check for duplicate mapping keys as it didn't work correctly anyway.
2006-08-03 16:07:29 +00:00
Kirill Simonov
2e6c774c92 Fix a bug when a block scalar is incorrectly emitted in the simple key context. 2006-07-30 12:51:05 +00:00
Kirill Simonov
e4c1238d2f Update libyaml bindings. 2006-07-21 13:52:03 +00:00
Kirill Simonov
6743cf6181 Update PyRex based bindings to libyaml to include Parser functions. 2006-07-07 19:39:29 +00:00
Kirill Simonov
63fa1bd6fe To make porting easier, rewrite Parser not using generators.
Fix handling of unexpected block mapping values, like
{{{
: foo
}}}

Remove obsolete and unused {{{__iter__}}} functions.
2006-07-03 11:29:45 +00:00
Kirill Simonov
27de2ba1fc Fix invalid output of single-quoted scalars in cases when a single
quote is not escaped when preceeded by whitespaces or line breaks.
(Fix #17).
2006-06-30 08:10:36 +00:00
Kirill Simonov
4b48dcfb5f Add pyrex-based bindings for the libyaml scanner. 2006-06-19 20:30:29 +00:00
Kirill Simonov
bcfc0b6dda Fix several problems caused by ill-formed documents.
The line number is not calculated correctly for DOS-style line breaks.

Fix error reporting in '''remove_possible_simple_key'''. The problem is caused by the document:

{{{
+foo: &A bar
+*A ]
}}}

Raise an error for a complex key which is not indented correctly, for instance:

{{{
? "foo"
 : "bar"
}}}
2006-06-16 07:23:05 +00:00
Kirill Simonov
d01a85fe5c Add ind and qnan values to a float test. 2006-05-24 15:45:38 +00:00
Kirill Simonov
a109c6bfce Add a test case belonging to the previous commit. 2006-05-22 19:50:32 +00:00