[Pkg-javascript-commits] [node-js-yaml] 01/08: New upstream version 3.9.1+dfsg
Ross Gammon
ross-guest at moszumanska.debian.org
Tue Aug 15 20:34:15 UTC 2017
This is an automated email from the git hooks/post-receive script.
ross-guest pushed a commit to branch master
in repository node-js-yaml.
commit d5e310317f8d3febcd8a74ae6062e5514aa80065
Author: Ross Gammon <rossgammon at mail.dk>
Date: Tue Aug 15 19:54:24 2017 +0200
New upstream version 3.9.1+dfsg
---
.eslintrc.yml | 1 +
.travis.yml | 5 +--
CHANGELOG.md | 47 +++++++++++++++++++++
README.md | 72 ++++++++++++++++++++-------------
examples/sample_document.yml | 2 +-
lib/js-yaml/dumper.js | 14 +++++--
lib/js-yaml/exception.js | 10 ++---
lib/js-yaml/loader.js | 33 ++++++++++-----
lib/js-yaml/type/binary.js | 5 ++-
lib/js-yaml/type/float.js | 17 ++++++--
lib/js-yaml/type/int.js | 12 ++++--
package.json | 18 ++++-----
test/issues/0085.js | 6 ++-
test/issues/0217.js | 4 +-
test/issues/0243-basic.yml | 15 +++++++
test/issues/0243-nested.yml | 15 +++++++
test/issues/0243.js | 29 +++++++++++++
test/issues/0266.js | 6 ++-
test/issues/0333.js | 17 ++++++++
test/issues/0333.yml | 3 ++
test/issues/0335.js | 20 +++++++++
test/issues/0335.yml | 6 +++
test/issues/0342.js | 61 ++++++++++++++++++++++++++++
test/issues/0346.js | 19 +++++++++
test/issues/0350.js | 13 ++++++
test/issues/0350.yml | 4 ++
test/issues/0351.js | 17 ++++++++
test/issues/0351.yml | 4 ++
test/samples-common/construct-binary.js | 9 ++++-
test/units/dump-scalar-styles.js | 18 ++++-----
30 files changed, 418 insertions(+), 84 deletions(-)
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 180dfaa..2ff9e07 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -1,6 +1,7 @@
env:
node: true
browser: true
+ es6: false
rules:
accessor-pairs: 2
diff --git a/.travis.yml b/.travis.yml
index 9c1a7b6..2eedb38 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,6 @@
sudo: false
language: node_js
node_js:
- - '0.10'
- - '0.12'
- '4'
- - '5'
+ - '6'
+ - '8'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 103b1bb..ab74736 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,50 @@
+3.9.1 / 2017-07-08
+------------------
+
+- Ensure stack is present for custom errors in node 7.+, #351.
+
+
+3.9.0 / 2017-07-08
+------------------
+
+- Add `condenseFlow` option (to create pretty URL query params), #346.
+- Support array return from safeLoadAll/loadAll, #350.
+
+
+3.8.4 / 2017-05-08
+------------------
+
+- Dumper: prevent space after dash for arrays that wrap, #343.
+
+
+3.8.3 / 2017-04-05
+------------------
+
+- Should not allow numbers to begin and end with underscore, #335.
+
+
+3.8.2 / 2017-03-02
+------------------
+
+- Fix `!!float 123` (integers) parse, #333.
+- Don't allow leading zeros in floats (except 0, 0.xxx).
+- Allow positive exponent without sign in floats.
+
+
+3.8.1 / 2017-02-07
+------------------
+
+- Maintenance: update browserified build.
+
+
+3.8.0 / 2017-02-07
+------------------
+
+- Fix reported position for `duplicated mapping key` errors.
+ Now points to block start instead of block end.
+ (#243, thanks to @shockey).
+
+
3.7.0 / 2016-11-12
------------------
diff --git a/README.md b/README.md
index 45c3502..170c164 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ JS-YAML - YAML 1.2 parser / writer for JavaScript
__[Online Demo](http://nodeca.github.com/js-yaml/)__
-This is an implementation of [YAML](http://yaml.org/), a human friendly data
+This is an implementation of [YAML](http://yaml.org/), a human-friendly data
serialization language. Started as [PyYAML](http://pyyaml.org/) port, it was
completely rewritten from scratch. Now it's very fast, and supports 1.2 spec.
@@ -57,7 +57,7 @@ var doc = jsyaml.load('greeting: hello\nname: world');
</script>
```
-Browser support was done mostly for online demo. If you find any errors - feel
+Browser support was done mostly for the online demo. If you find any errors - feel
free to send pull requests with fixes. Also note, that IE and other old browsers
needs [es5-shims](https://github.com/kriskowal/es5-shim) to operate.
@@ -122,17 +122,17 @@ NOTE: This function **does not** understand multi-document sources, it throws
exception on those.
NOTE: JS-YAML **does not** support schema-specific tag resolution restrictions.
-So, JSON schema is not as strict as defined in the YAML specification.
+So, the JSON schema is not as strictly defined in the YAML specification.
It allows numbers in any notation, use `Null` and `NULL` as `null`, etc.
-Core schema also has no such restrictions. It allows binary notation for integers.
+The core schema also has no such restrictions. It allows binary notation for integers.
### load (string [ , options ])
**Use with care with untrusted sources**. The same as `safeLoad()` but uses
`DEFAULT_FULL_SCHEMA` by default - adds some JavaScript-specific types:
-`!!js/function`, `!!js/regexp` and `!!js/undefined`. For untrusted sources you
-must additionally validate object structure, to avoid injections:
+`!!js/function`, `!!js/regexp` and `!!js/undefined`. For untrusted sources, you
+must additionally validate object structure to avoid injections:
``` javascript
var untrusted_code = '"toString": !<tag:yaml.org,2002:js/function> "function (){very_evil_thing();}"';
@@ -142,10 +142,10 @@ require('js-yaml').load(untrusted_code) + ''
```
-### safeLoadAll (string, iterator [ , options ])
+### safeLoadAll (string [, iterator] [, options ])
-Same as `safeLoad()`, but understands multi-document sources and apply
-`iterator` to each document.
+Same as `safeLoad()`, but understands multi-document sources. Applies
+`iterator` to each document if specified, or returns aray of documents.
``` javascript
var yaml = require('js-yaml');
@@ -156,16 +156,16 @@ yaml.safeLoadAll(data, function (doc) {
```
-### loadAll (string, iterator [ , options ])
+### loadAll (string [, iterator] [ , options ])
Same as `safeLoadAll()` but uses `DEFAULT_FULL_SCHEMA` by default.
### safeDump (object [ , options ])
-Serializes `object` as YAML document. Uses `DEFAULT_SAFE_SCHEMA`, so it will
-throw exception if you try to dump regexps or functions. However, you can
-disable exceptions by `skipInvalid` option.
+Serializes `object` as a YAML document. Uses `DEFAULT_SAFE_SCHEMA`, so it will
+throw an exception if you try to dump regexps or functions. However, you can
+disable exceptions by setting the `skipInvalid` option to `true`.
options:
@@ -182,28 +182,46 @@ options:
- `noRefs` _(default: `false`)_ - if `true`, don't convert duplicate objects into references
- `noCompatMode` _(default: `false`)_ - if `true` don't try to be compatible with older
yaml versions. Currently: don't quote "yes", "no" and so on, as required for YAML 1.1
+- `condenseFlow` _(default: `false`)_ - if `true` flow sequences will be condensed, omitting the space between `key: value` or `a, b`. Eg. `'[a,b]'` or `{a:{b:c}}`. Can be useful when using yaml for pretty URL query params as spaces are %-encoded.
-styles:
+The following table show availlable styles (e.g. "canonical",
+"binary"...) available for each tag (.e.g. !!null, !!int ...). Yaml
+ouput is shown on the right side after `=>` (default setting) or `->`:
``` none
!!null
- "canonical" => "~"
+ "canonical" -> "~"
+ "lowercase" => "null"
+ "uppercase" -> "NULL"
+ "camelcase" -> "Null"
!!int
- "binary" => "0b1", "0b101010", "0b1110001111010"
- "octal" => "01", "052", "016172"
+ "binary" -> "0b1", "0b101010", "0b1110001111010"
+ "octal" -> "01", "052", "016172"
"decimal" => "1", "42", "7290"
- "hexadecimal" => "0x1", "0x2A", "0x1C7A"
+ "hexadecimal" -> "0x1", "0x2A", "0x1C7A"
-!!null, !!bool, !!float
- "lowercase" => "null", "true", "false", ".nan", '.inf'
- "uppercase" => "NULL", "TRUE", "FALSE", ".NAN", '.INF'
- "camelcase" => "Null", "True", "False", ".NaN", '.Inf'
-```
+!!bool
+ "lowercase" => "true", "false"
+ "uppercase" -> "TRUE", "FALSE"
+ "camelcase" -> "True", "False"
-By default, !!int uses `decimal`, and !!null, !!bool, !!float use `lowercase`.
+!!float
+ "lowercase" => ".nan", '.inf'
+ "uppercase" -> ".NAN", '.INF'
+ "camelcase" -> ".NaN", '.Inf'
+```
+Example:
+``` javascript
+safeDump (object, {
+ 'styles': {
+ '!!null': 'canonical' // dump null as ~
+ },
+ 'sortKeys': true // sort object keys
+});
+```
### dump (object [ , options ])
@@ -244,7 +262,7 @@ Caveats
-------
Note, that you use arrays or objects as key in JS-YAML. JS does not allow objects
-or array as keys, and stringifies (by calling .toString method) them at the
+or arrays as keys, and stringifies (by calling .toString method) them at the
moment of adding them.
``` yaml
@@ -276,14 +294,14 @@ Breaking changes in 2.x.x -> 3.x.x
----------------------------------
If you have not used __custom__ tags or loader classes and not loaded yaml
-files via `require()` - no changes needed. Just upgrade library.
+files via `require()`, no changes are needed. Just upgrade the library.
Otherwise, you should:
1. Replace all occurences of `require('xxxx.yml')` by `fs.readFileSync()` +
`yaml.safeLoad()`.
2. rewrite your custom tags constructors and custom loader
- classes, to conform new API. See
+ classes, to conform the new API. See
[examples](https://github.com/nodeca/js-yaml/tree/master/examples) and
[wiki](https://github.com/nodeca/js-yaml/wiki) for details.
diff --git a/examples/sample_document.yml b/examples/sample_document.yml
index 4479ee9..7abaa89 100644
--- a/examples/sample_document.yml
+++ b/examples/sample_document.yml
@@ -98,7 +98,7 @@ bool:
float:
canonical: 6.8523015e+5
- exponentioal: 685.230_15e+03
+ exponential: 685.230_15e+03
fixed: 685_230.15
sexagesimal: 190:20:30.15
negative infinity: -.inf
diff --git a/lib/js-yaml/dumper.js b/lib/js-yaml/dumper.js
index 203f436..6e60bbd 100644
--- a/lib/js-yaml/dumper.js
+++ b/lib/js-yaml/dumper.js
@@ -114,6 +114,7 @@ function State(options) {
this.lineWidth = options['lineWidth'] || 80;
this.noRefs = options['noRefs'] || false;
this.noCompatMode = options['noCompatMode'] || false;
+ this.condenseFlow = options['condenseFlow'] || false;
this.implicitTypes = this.schema.compiledImplicit;
this.explicitTypes = this.schema.compiledExplicit;
@@ -483,7 +484,7 @@ function writeFlowSequence(state, level, object) {
for (index = 0, length = object.length; index < length; index += 1) {
// Write only valid elements.
if (writeNode(state, level, object[index], false, false)) {
- if (index !== 0) _result += ', ';
+ if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : '');
_result += state.dump;
}
}
@@ -504,7 +505,14 @@ function writeBlockSequence(state, level, object, compact) {
if (!compact || index !== 0) {
_result += generateNextLine(state, level);
}
- _result += '- ' + state.dump;
+
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
+ _result += '-';
+ } else {
+ _result += '- ';
+ }
+
+ _result += state.dump;
}
}
@@ -536,7 +544,7 @@ function writeFlowMapping(state, level, object) {
if (state.dump.length > 1024) pairBuffer += '? ';
- pairBuffer += state.dump + ': ';
+ pairBuffer += state.dump + ':' + (state.condenseFlow ? '' : ' ');
if (!writeNode(state, level, objectValue, false, false)) {
continue; // Skip this pair because of invalid value.
diff --git a/lib/js-yaml/exception.js b/lib/js-yaml/exception.js
index cf4e625..b744a1e 100644
--- a/lib/js-yaml/exception.js
+++ b/lib/js-yaml/exception.js
@@ -6,6 +6,11 @@ function YAMLException(reason, mark) {
// Super constructor
Error.call(this);
+ this.name = 'YAMLException';
+ this.reason = reason;
+ this.mark = mark;
+ this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
+
// Include stack trace in error object
if (Error.captureStackTrace) {
// Chrome and NodeJS
@@ -14,11 +19,6 @@ function YAMLException(reason, mark) {
// FF, IE 10+ and Safari 6+. Fallback for others
this.stack = (new Error()).stack || '';
}
-
- this.name = 'YAMLException';
- this.reason = reason;
- this.mark = mark;
- this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
}
diff --git a/lib/js-yaml/loader.js b/lib/js-yaml/loader.js
index 70e1a56..9188da1 100644
--- a/lib/js-yaml/loader.js
+++ b/lib/js-yaml/loader.js
@@ -86,6 +86,7 @@ function fromDecimalCode(c) {
}
function simpleEscapeSequence(c) {
+ /* eslint-disable indent */
return (c === 0x30/* 0 */) ? '\x00' :
(c === 0x61/* a */) ? '\x07' :
(c === 0x62/* b */) ? '\x08' :
@@ -112,8 +113,10 @@ function charFromCodepoint(c) {
}
// Encode UTF-16 surrogate pair
// https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
- return String.fromCharCode(((c - 0x010000) >> 10) + 0xD800,
- ((c - 0x010000) & 0x03FF) + 0xDC00);
+ return String.fromCharCode(
+ ((c - 0x010000) >> 10) + 0xD800,
+ ((c - 0x010000) & 0x03FF) + 0xDC00
+ );
}
var simpleEscapeCheck = new Array(256); // integer, for fast access
@@ -245,9 +248,7 @@ function captureSegment(state, start, end, checkJson) {
_result = state.input.slice(start, end);
if (checkJson) {
- for (_position = 0, _length = _result.length;
- _position < _length;
- _position += 1) {
+ for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
_character = _result.charCodeAt(_position);
if (!(_character === 0x09 ||
(0x20 <= _character && _character <= 0x10FFFF))) {
@@ -281,7 +282,7 @@ function mergeMappings(state, destination, source, overridableKeys) {
}
}
-function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode) {
+function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
var index, quantity;
keyNode = String(keyNode);
@@ -302,6 +303,8 @@ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valu
if (!state.json &&
!_hasOwnProperty.call(overridableKeys, keyNode) &&
_hasOwnProperty.call(_result, keyNode)) {
+ state.line = startLine || state.line;
+ state.position = startPos || state.position;
throwError(state, 'duplicated mapping key');
}
_result[keyNode] = valueNode;
@@ -949,6 +952,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
var following,
allowCompact,
_line,
+ _pos,
_tag = state.tag,
_anchor = state.anchor,
_result = {},
@@ -969,6 +973,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
while (ch !== 0) {
following = state.input.charCodeAt(state.position + 1);
_line = state.line; // Save the current line.
+ _pos = state.position;
//
// Explicit notation case. There are two separate blocks:
@@ -1063,7 +1068,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
}
if (!atExplicitKey) {
- storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
keyTag = keyNode = valueNode = null;
}
@@ -1361,9 +1366,7 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
if (state.tag !== null && state.tag !== '!') {
if (state.tag === '?') {
- for (typeIndex = 0, typeQuantity = state.implicitTypes.length;
- typeIndex < typeQuantity;
- typeIndex += 1) {
+ for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
type = state.implicitTypes[typeIndex];
// Implicit resolving is not allowed for non-scalar types, and '?'
@@ -1552,6 +1555,10 @@ function loadDocuments(input, options) {
function loadAll(input, iterator, options) {
var documents = loadDocuments(input, options), index, length;
+ if (typeof iterator !== 'function') {
+ return documents;
+ }
+
for (index = 0, length = documents.length; index < length; index += 1) {
iterator(documents[index]);
}
@@ -1572,7 +1579,11 @@ function load(input, options) {
function safeLoadAll(input, output, options) {
- loadAll(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
+ if (typeof output === 'function') {
+ loadAll(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
+ } else {
+ return loadAll(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
+ }
}
diff --git a/lib/js-yaml/type/binary.js b/lib/js-yaml/type/binary.js
index 205629f..10b1875 100644
--- a/lib/js-yaml/type/binary.js
+++ b/lib/js-yaml/type/binary.js
@@ -75,7 +75,10 @@ function constructYamlBinary(data) {
}
// Wrap into Buffer for NodeJS and leave Array for browser
- if (NodeBuffer) return new NodeBuffer(result);
+ if (NodeBuffer) {
+ // Support node 6.+ Buffer API when available
+ return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
+ }
return result;
}
diff --git a/lib/js-yaml/type/float.js b/lib/js-yaml/type/float.js
index 7687154..127671b 100644
--- a/lib/js-yaml/type/float.js
+++ b/lib/js-yaml/type/float.js
@@ -4,16 +4,27 @@ var common = require('../common');
var Type = require('../type');
var YAML_FLOAT_PATTERN = new RegExp(
- '^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' +
- '|\\.[0-9_]+(?:[eE][-+][0-9]+)?' +
+ // 2.5e4, 2.5 and integers
+ '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
+ // .2e4, .2
+ // special case, seems not from spec
+ '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
+ // 20:59
'|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
+ // .inf
'|[-+]?\\.(?:inf|Inf|INF)' +
+ // .nan
'|\\.(?:nan|NaN|NAN))$');
function resolveYamlFloat(data) {
if (data === null) return false;
- if (!YAML_FLOAT_PATTERN.test(data)) return false;
+ if (!YAML_FLOAT_PATTERN.test(data) ||
+ // Quick hack to not allow integers end with `_`
+ // Probably should update regexp & check speed
+ data[data.length - 1] === '_') {
+ return false;
+ }
return true;
}
diff --git a/lib/js-yaml/type/int.js b/lib/js-yaml/type/int.js
index a3c4965..4ae522a 100644
--- a/lib/js-yaml/type/int.js
+++ b/lib/js-yaml/type/int.js
@@ -51,7 +51,7 @@ function resolveYamlInteger(data) {
if (ch !== '0' && ch !== '1') return false;
hasDigits = true;
}
- return hasDigits;
+ return hasDigits && ch !== '_';
}
@@ -65,7 +65,7 @@ function resolveYamlInteger(data) {
if (!isHexCode(data.charCodeAt(index))) return false;
hasDigits = true;
}
- return hasDigits;
+ return hasDigits && ch !== '_';
}
// base 8
@@ -75,11 +75,14 @@ function resolveYamlInteger(data) {
if (!isOctCode(data.charCodeAt(index))) return false;
hasDigits = true;
}
- return hasDigits;
+ return hasDigits && ch !== '_';
}
// base 10 (except 0) or base 60
+ // value should not start with `_`;
+ if (ch === '_') return false;
+
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
@@ -90,7 +93,8 @@ function resolveYamlInteger(data) {
hasDigits = true;
}
- if (!hasDigits) return false;
+ // Should have digits and should not end with `_`
+ if (!hasDigits || ch === '_') return false;
// if !base60 - done;
if (ch !== ':') return true;
diff --git a/package.json b/package.json
index 1c6deb1..92b4cd2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "js-yaml",
- "version": "3.7.0",
+ "version": "3.9.1",
"description": "YAML 1.2 parser and serializer",
"keywords": [
"yaml",
@@ -28,17 +28,17 @@
},
"dependencies": {
"argparse": "^1.0.7",
- "esprima": "^2.6.0"
+ "esprima": "^4.0.0"
},
"devDependencies": {
- "ansi": "*",
- "benchmark": "*",
- "browserify": "^13.0.0",
+ "ansi": "^0.3.1",
+ "benchmark": "^2.1.4",
+ "browserify": "^14.3.0",
"codemirror": "^5.13.4",
- "eslint": "^2.8.0",
- "istanbul": "*",
- "mocha": "*",
- "uglify-js": "^2.6.1"
+ "eslint": "^4.1.1",
+ "istanbul": "^0.4.5",
+ "mocha": "^3.3.0",
+ "uglify-js": "^3.0.1"
},
"scripts": {
"test": "make test"
diff --git a/test/issues/0085.js b/test/issues/0085.js
index 68de8a1..403b7e4 100644
--- a/test/issues/0085.js
+++ b/test/issues/0085.js
@@ -15,8 +15,10 @@ test('Dumper should take into account booleans syntax from YAML 1.0/1.1', functi
DEPRECATED_BOOLEANS_SYNTAX.forEach(function (string) {
var dump = yaml.dump(string).trim();
- assert(((dump === "'" + string + "'") || (dump === '"' + string + '"')),
- ('"' + string + '" string is dumped without quoting; actual dump: ' + dump));
+ assert(
+ ((dump === "'" + string + "'") || (dump === '"' + string + '"')),
+ ('"' + string + '" string is dumped without quoting; actual dump: ' + dump)
+ );
});
});
diff --git a/test/issues/0217.js b/test/issues/0217.js
index 95d85a7..b3b11d1 100644
--- a/test/issues/0217.js
+++ b/test/issues/0217.js
@@ -79,8 +79,8 @@ test('Folding Javascript functions preserves content', function () {
assertFunctionPreserved(fnRot13,
[ 'nggnpxngqnja', 'orjnergurvqrfbsznepu' ],
- [ 'attackatdawn', 'bewaretheidesofmarch' ]
- , 'ROT13');
+ [ 'attackatdawn', 'bewaretheidesofmarch' ],
+ 'ROT13');
});
test('Folding long regular expressions preserves content', function () {
diff --git a/test/issues/0243-basic.yml b/test/issues/0243-basic.yml
new file mode 100644
index 0000000..ee98211
--- /dev/null
+++ b/test/issues/0243-basic.yml
@@ -0,0 +1,15 @@
+a:
+ b: 1
+ c: 2
+d:
+ e: 3
+ f: 4
+duplicate: # 1
+ id: 1234
+ note: "this is the first one, so it won't raise an error"
+duplicate: # 2
+ id: 5678
+ note: "this is the second one, so it will raise an error, hopefully at the start of the key"
+g:
+ h: 5
+ i: 6
diff --git a/test/issues/0243-nested.yml b/test/issues/0243-nested.yml
new file mode 100644
index 0000000..b24c33b
--- /dev/null
+++ b/test/issues/0243-nested.yml
@@ -0,0 +1,15 @@
+a:
+ b: 1
+ c: 2
+d:
+ e: 3
+ f: 4
+ duplicate: # 1
+ id: 1234
+ note: "this is the first one, so it won't raise an error"
+ duplicate: # 2
+ id: 5678
+ note: "this is the second one, so it will raise an error, hopefully at the start of the key"
+g:
+ h: 5
+ i: 6
diff --git a/test/issues/0243.js b/test/issues/0243.js
new file mode 100644
index 0000000..a25723f
--- /dev/null
+++ b/test/issues/0243.js
@@ -0,0 +1,29 @@
+'use strict';
+
+
+var assert = require('assert');
+var yaml = require('../../');
+var readFileSync = require('fs').readFileSync;
+
+
+test('Duplicated mapping key errors on top level throw at beginning of key', function () {
+ var src = readFileSync(require('path').join(__dirname, '/0243-basic.yml'), 'utf8');
+ var lines = src.split('\n');
+
+ try {
+ yaml.safeLoad(src);
+ } catch (e) {
+ assert.equal(lines[e.mark.line], 'duplicate: # 2');
+ }
+});
+
+test('Duplicated mapping key errors inside of mapping values throw at beginning of key', function () {
+ var src = readFileSync(require('path').join(__dirname, '/0243-nested.yml'), 'utf8');
+ var lines = src.split('\n');
+
+ try {
+ yaml.safeLoad(src);
+ } catch (e) {
+ assert.equal(lines[e.mark.line], ' duplicate: # 2');
+ }
+});
diff --git a/test/issues/0266.js b/test/issues/0266.js
index 9422d98..8d81898 100644
--- a/test/issues/0266.js
+++ b/test/issues/0266.js
@@ -15,7 +15,9 @@ test('Dumper should not take into account booleans syntax from YAML 1.0/1.1 in n
DEPRECATED_BOOLEANS_SYNTAX.forEach(function (string) {
var dump = yaml.dump(string, { noCompatMode: true }).trim();
- assert((dump === string),
- ('"' + string + '" string is not dumped as-is; actual dump: ' + dump));
+ assert(
+ (dump === string),
+ ('"' + string + '" string is not dumped as-is; actual dump: ' + dump)
+ );
});
});
diff --git a/test/issues/0333.js b/test/issues/0333.js
new file mode 100644
index 0000000..92ce7de
--- /dev/null
+++ b/test/issues/0333.js
@@ -0,0 +1,17 @@
+'use strict';
+
+
+var assert = require('assert');
+var yaml = require('../../');
+var readFileSync = require('fs').readFileSync;
+
+
+test('should allow cast integers as !!float', function () {
+ var data = yaml.safeLoad(readFileSync(require('path').join(__dirname, '/0333.yml'), 'utf8'));
+
+ assert.deepEqual(data, {
+ negative: -1,
+ zero: 0,
+ positive: 23000
+ });
+});
diff --git a/test/issues/0333.yml b/test/issues/0333.yml
new file mode 100644
index 0000000..6ff2662
--- /dev/null
+++ b/test/issues/0333.yml
@@ -0,0 +1,3 @@
+negative: !!float -1
+zero: !!float 0
+positive: !!float 2.3e4
diff --git a/test/issues/0335.js b/test/issues/0335.js
new file mode 100644
index 0000000..281eac3
--- /dev/null
+++ b/test/issues/0335.js
@@ -0,0 +1,20 @@
+'use strict';
+
+
+var assert = require('assert');
+var yaml = require('../../');
+var readFileSync = require('fs').readFileSync;
+
+
+test('Don\'t throw on warning', function () {
+ var src = readFileSync(require('path').join(__dirname, '/0335.yml'), 'utf8');
+
+ assert.deepEqual(yaml.safeLoad(src), {
+ not_num_1: '-_123',
+ not_num_2: '_123',
+ not_num_3: '123_',
+ not_num_4: '0b00_',
+ not_num_5: '0x00_',
+ not_num_6: '011_'
+ });
+});
diff --git a/test/issues/0335.yml b/test/issues/0335.yml
new file mode 100644
index 0000000..a4b30b6
--- /dev/null
+++ b/test/issues/0335.yml
@@ -0,0 +1,6 @@
+not_num_1: -_123
+not_num_2: _123
+not_num_3: 123_
+not_num_4: 0b00_
+not_num_5: 0x00_
+not_num_6: 011_
diff --git a/test/issues/0342.js b/test/issues/0342.js
new file mode 100644
index 0000000..4182682
--- /dev/null
+++ b/test/issues/0342.js
@@ -0,0 +1,61 @@
+'use strict';
+
+
+var assert = require('assert');
+var yaml = require('../../');
+var simpleArray = [ 'a', 'b' ];
+var arrayOfSimpleObj = [ { a: 1 }, { b: 2 } ];
+var arrayOfObj = [ { a: 1, b: 'abc' }, { c: 'def', d: 2 } ];
+
+
+test('space should be added for array, regardless of indent', function () {
+ assert.deepEqual(
+ yaml.dump(simpleArray, { indent: 1 }),
+ '- a\n- b\n'
+ );
+ assert.deepEqual(
+ yaml.dump(simpleArray, { indent: 2 }),
+ '- a\n- b\n'
+ );
+ assert.deepEqual(
+ yaml.dump(simpleArray, { indent: 3 }),
+ '- a\n- b\n'
+ );
+ assert.deepEqual(
+ yaml.dump(simpleArray, { indent: 4 }),
+ '- a\n- b\n'
+ );
+});
+
+test('array of objects should not wrap at indentation of 2', function () {
+ assert.deepEqual(
+ yaml.dump(arrayOfSimpleObj, { indent: 2 }),
+ '- a: 1\n- b: 2\n'
+ );
+ assert.deepEqual(
+ yaml.dump(arrayOfObj, { indent: 2 }),
+ '- a: 1\n b: abc\n- c: def\n d: 2\n'
+ );
+});
+
+test('EOL space should not be added on array of objects at indentation of 3', function () {
+ assert.deepEqual(
+ yaml.dump(arrayOfSimpleObj, { indent: 3 }),
+ '-\n a: 1\n-\n b: 2\n'
+ );
+ assert.deepEqual(
+ yaml.dump(arrayOfObj, { indent: 3 }),
+ '-\n a: 1\n b: abc\n-\n c: def\n d: 2\n'
+ );
+});
+
+test('EOL space should not be added on array of objects at indentation of 4', function () {
+ assert.deepEqual(
+ yaml.dump(arrayOfSimpleObj, { indent: 4 }),
+ '-\n a: 1\n-\n b: 2\n'
+ );
+ assert.deepEqual(
+ yaml.dump(arrayOfObj, { indent: 4 }),
+ '-\n a: 1\n b: abc\n-\n c: def\n d: 2\n'
+ );
+});
diff --git a/test/issues/0346.js b/test/issues/0346.js
new file mode 100644
index 0000000..7b3ebed
--- /dev/null
+++ b/test/issues/0346.js
@@ -0,0 +1,19 @@
+'use strict';
+
+var assert = require('assert');
+var yaml = require('../../');
+
+
+test('should not emit spaces in arrays in flow mode between entries using condenseFlow: true', function () {
+ assert.equal(
+ yaml.dump([ 'a', 'b' ], { flowLevel: 0, indent: 0, condenseFlow: true }),
+ '[a,b]\n'
+ );
+});
+
+test('should not emit spaces between key: value in objects in flow sequence using condenseFlow: true', function () {
+ assert.equal(
+ yaml.dump({ a: { b: 'c' } }, { flowLevel: 0, indent: 0, condenseFlow: true }),
+ '{a:{b:c}}\n'
+ );
+});
diff --git a/test/issues/0350.js b/test/issues/0350.js
new file mode 100644
index 0000000..891f99e
--- /dev/null
+++ b/test/issues/0350.js
@@ -0,0 +1,13 @@
+'use strict';
+
+
+var assert = require('assert');
+var yaml = require('../../');
+var readFileSync = require('fs').readFileSync;
+
+
+test('should allow cast integers as !!float', function () {
+ var data = yaml.safeLoadAll(readFileSync(require('path').join(__dirname, '/0350.yml'), 'utf8'));
+
+ assert.deepEqual(data, [ { a: 1 }, { b: 2 } ]);
+});
diff --git a/test/issues/0350.yml b/test/issues/0350.yml
new file mode 100644
index 0000000..d3f18ac
--- /dev/null
+++ b/test/issues/0350.yml
@@ -0,0 +1,4 @@
+---
+a: 1
+---
+b: 2
diff --git a/test/issues/0351.js b/test/issues/0351.js
new file mode 100644
index 0000000..58fc65a
--- /dev/null
+++ b/test/issues/0351.js
@@ -0,0 +1,17 @@
+'use strict';
+
+
+var assert = require('assert');
+var yaml = require('../..');
+var readFileSync = require('fs').readFileSync;
+
+
+test('should include the error message in the error stack', function () {
+ try {
+ yaml.safeLoad(readFileSync(require('path').join(__dirname, '/0351.yml'), 'utf8'));
+ } catch (err) {
+ assert(err.stack.startsWith('YAMLException: end of the stream or a document separator is expected'));
+ return;
+ }
+ assert.fail(null, null, 'Expected an error to be thrown');
+});
diff --git a/test/issues/0351.yml b/test/issues/0351.yml
new file mode 100644
index 0000000..8ab27b9
--- /dev/null
+++ b/test/issues/0351.yml
@@ -0,0 +1,4 @@
+# intentionally invalid yaml
+
+ foo: bar
+baz: qux
diff --git a/test/samples-common/construct-binary.js b/test/samples-common/construct-binary.js
index caf2e2b..821712e 100644
--- a/test/samples-common/construct-binary.js
+++ b/test/samples-common/construct-binary.js
@@ -2,10 +2,15 @@
/*eslint-disable max-len*/
+// Support node 6.+ Buffer API when available
+function buffer(data, encoding) {
+ return Buffer.from ? Buffer.from(data, encoding) : new Buffer(data, encoding);
+}
+
module.exports = {
- canonical: new Buffer("GIF89a\x0c\x00\x0c\x00\x84\x00\x00\xff\xff\xf7\xf5\xf5\xee\xe9\xe9\xe5fff\x00\x00\x00\xe7\xe7\xe7^^^\xf3\xf3\xed\x8e\x8e\x8e\xe0\xe0\xe0\x9f\x9f\x9f\x93\x93\x93\xa7\xa7\xa7\x9e\x9e\x9eiiiccc\xa3\xa3\xa3\x84\x84\x84\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9!\xfe\x0eMade with GIMP\x00,\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x05, \x8e\x810\x9e\ [...]
+ canonical: buffer("GIF89a\x0c\x00\x0c\x00\x84\x00\x00\xff\xff\xf7\xf5\xf5\xee\xe9\xe9\xe5fff\x00\x00\x00\xe7\xe7\xe7^^^\xf3\xf3\xed\x8e\x8e\x8e\xe0\xe0\xe0\x9f\x9f\x9f\x93\x93\x93\xa7\xa7\xa7\x9e\x9e\x9eiiiccc\xa3\xa3\xa3\x84\x84\x84\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9!\xfe\x0eMade with GIMP\x00,\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x05, \x8e\x810\x9e\xe3@ [...]
- generic: new Buffer("GIF89a\x0c\x00\x0c\x00\x84\x00\x00\xff\xff\xf7\xf5\xf5\xee\xe9\xe9\xe5fff\x00\x00\x00\xe7\xe7\xe7^^^\xf3\xf3\xed\x8e\x8e\x8e\xe0\xe0\xe0\x9f\x9f\x9f\x93\x93\x93\xa7\xa7\xa7\x9e\x9e\x9eiiiccc\xa3\xa3\xa3\x84\x84\x84\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9!\xfe\x0eMade with GIMP\x00,\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x05, \x8e\x810\x9e\xe [...]
+ generic: buffer("GIF89a\x0c\x00\x0c\x00\x84\x00\x00\xff\xff\xf7\xf5\xf5\xee\xe9\xe9\xe5fff\x00\x00\x00\xe7\xe7\xe7^^^\xf3\xf3\xed\x8e\x8e\x8e\xe0\xe0\xe0\x9f\x9f\x9f\x93\x93\x93\xa7\xa7\xa7\x9e\x9e\x9eiiiccc\xa3\xa3\xa3\x84\x84\x84\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9\xff\xfe\xf9!\xfe\x0eMade with GIMP\x00,\x00\x00\x00\x00\x0c\x00\x0c\x00\x00\x05, \x8e\x810\x9e\xe3@\x [...]
description: 'The binary value above is a tiny arrow encoded as a gif image.'
};
diff --git a/test/units/dump-scalar-styles.js b/test/units/dump-scalar-styles.js
index c77e8de..49f178a 100644
--- a/test/units/dump-scalar-styles.js
+++ b/test/units/dump-scalar-styles.js
@@ -197,16 +197,16 @@ suite('Scalar style dump:', function () {
var indeed = repeat('word. ', 31) + '\n' +
[ 2, 3, 5, 7, 11, 13, 17 ]
- .map(function (n) { return repeat(' ', n); })
- .join('\n');
+ .map(function (n) { return repeat(' ', n); })
+ .join('\n');
assert.strictEqual(dump(indeed),
- '>-\n' + indent(
- 'word. word. word. word. word. word. word. word. word. word. word. word. word.\n' +
- 'word. word. word. word. word. word. word. word. word. word. word. word. word.\n' +
- 'word. word. word. word. word. \n' +
- [ 2, 3, 5, 7, 11, 13, 17 ]
- .map(function (n) { return repeat(' ', n); })
- .join('\n') + '\n'));
+ '>-\n' + indent(
+ 'word. word. word. word. word. word. word. word. word. word. word. word. word.\n' +
+ 'word. word. word. word. word. word. word. word. word. word. word. word. word.\n' +
+ 'word. word. word. word. word. \n' +
+ [ 2, 3, 5, 7, 11, 13, 17 ]
+ .map(function (n) { return repeat(' ', n); })
+ .join('\n') + '\n'));
});
var story = 'Call me Ishmael. Some years ago—never mind how long precisely—'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-js-yaml.git
More information about the Pkg-javascript-commits
mailing list