[Pkg-javascript-commits] [node-js-yaml] 01/03: New upstream version 3.10.0+dfsg

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 14 19:14:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-js-yaml.

commit 3343e5e55963cbaa5bf321090b5b96ea146b8abb
Author: Bastien ROUCARIÈS <roucaries.bastien at gmail.com>
Date:   Thu Sep 14 21:05:56 2017 +0200

    New upstream version 3.10.0+dfsg
---
 CHANGELOG.md          |  7 +++++++
 README.md             |  8 ++++----
 lib/js-yaml/dumper.js | 16 +++++++++++++---
 lib/js-yaml/loader.js |  2 +-
 package.json          |  2 +-
 test/issues/0346.js   | 14 ++++++++++----
 test/issues/0369.js   | 11 +++++++++++
 7 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ab74736..1f31dfe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+3.10.0 / 2017-09-10
+-------------------
+
+- Fix `condenseFlow` output (quote keys for sure, instead of spaces), #371, #370.
+- Dump astrals as codepoints instead of surrogate pair, #368.
+
+
 3.9.1 / 2017-07-08
 ------------------
 
diff --git a/README.md b/README.md
index 170c164..cf73ebd 100644
--- a/README.md
+++ b/README.md
@@ -145,7 +145,7 @@ require('js-yaml').load(untrusted_code) + ''
 ### safeLoadAll (string [, iterator] [, options ])
 
 Same as `safeLoad()`, but understands multi-document sources. Applies
-`iterator` to each document if specified, or returns aray of documents.
+`iterator` to each document if specified, or returns array of documents.
 
 ``` javascript
 var yaml = require('js-yaml');
@@ -182,7 +182,7 @@ 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.
+- `condenseFlow` _(default: `false`)_ - if `true` flow sequences will be condensed, omitting the space between `a, b`. Eg. `'[a,b]'`, and omitting the space between `key: value` and quoting the key. Eg. `'{"a":b}'` Can be useful when using yaml for pretty URL query params as spaces are %-encoded.
 
 The following table show availlable styles (e.g. "canonical",
 "binary"...) available for each tag (.e.g. !!null, !!int ...). Yaml
@@ -262,7 +262,7 @@ Caveats
 -------
 
 Note, that you use arrays or objects as key in JS-YAML. JS does not allow objects
-or arrays 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
@@ -298,7 +298,7 @@ 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()` +
+1. Replace all occurrences of `require('xxxx.yml')` by `fs.readFileSync()` +
   `yaml.safeLoad()`.
 2. rewrite your custom tags constructors and custom loader
   classes, to conform the new API. See
diff --git a/lib/js-yaml/dumper.js b/lib/js-yaml/dumper.js
index 6e60bbd..025b185 100644
--- a/lib/js-yaml/dumper.js
+++ b/lib/js-yaml/dumper.js
@@ -461,11 +461,21 @@ function foldLine(line, width) {
 // Escapes a double-quoted string.
 function escapeString(string) {
   var result = '';
-  var char;
+  var char, nextChar;
   var escapeSeq;
 
   for (var i = 0; i < string.length; i++) {
     char = string.charCodeAt(i);
+    // Check for surrogate pairs (reference Unicode 3.0 section "3.7 Surrogates").
+    if (char >= 0xD800 && char <= 0xDBFF/* high surrogate */) {
+      nextChar = string.charCodeAt(i + 1);
+      if (nextChar >= 0xDC00 && nextChar <= 0xDFFF/* low surrogate */) {
+        // Combine the surrogate pair and store it escaped.
+        result += encodeHex((char - 0xD800) * 0x400 + nextChar - 0xDC00 + 0x10000);
+        // Advance index one extra since we already used that char here.
+        i++; continue;
+      }
+    }
     escapeSeq = ESCAPE_SEQUENCES[char];
     result += !escapeSeq && isPrintable(char)
       ? string[i]
@@ -531,7 +541,7 @@ function writeFlowMapping(state, level, object) {
       pairBuffer;
 
   for (index = 0, length = objectKeyList.length; index < length; index += 1) {
-    pairBuffer = '';
+    pairBuffer = state.condenseFlow ? '"' : '';
 
     if (index !== 0) pairBuffer += ', ';
 
@@ -544,7 +554,7 @@ function writeFlowMapping(state, level, object) {
 
     if (state.dump.length > 1024) pairBuffer += '? ';
 
-    pairBuffer += state.dump + ':' + (state.condenseFlow ? '' : ' ');
+    pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
 
     if (!writeNode(state, level, objectValue, false, false)) {
       continue; // Skip this pair because of invalid value.
diff --git a/lib/js-yaml/loader.js b/lib/js-yaml/loader.js
index 9188da1..fe2cb4d 100644
--- a/lib/js-yaml/loader.js
+++ b/lib/js-yaml/loader.js
@@ -997,7 +997,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
         allowCompact = true;
 
       } else {
-        throwError(state, 'incomplete explicit mapping pair; a key node is missed');
+        throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
       }
 
       state.position += 1;
diff --git a/package.json b/package.json
index 92b4cd2..7c73636 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "js-yaml",
-  "version": "3.9.1",
+  "version": "3.10.0",
   "description": "YAML 1.2 parser and serializer",
   "keywords": [
     "yaml",
diff --git a/test/issues/0346.js b/test/issues/0346.js
index 7b3ebed..ccd75d5 100644
--- a/test/issues/0346.js
+++ b/test/issues/0346.js
@@ -5,15 +5,21 @@ var yaml = require('../../');
 
 
 test('should not emit spaces in arrays in flow mode between entries using condenseFlow: true', function () {
+  var array = [ 'a', 'b' ];
+  var dumpedArray = yaml.dump(array, { flowLevel: 0, indent: 0, condenseFlow: true });
   assert.equal(
-    yaml.dump([ 'a', 'b' ], { flowLevel: 0, indent: 0, condenseFlow: true }),
+    dumpedArray,
     '[a,b]\n'
   );
+  assert.deepEqual(yaml.load(dumpedArray), array);
 });
 
-test('should not emit spaces between key: value in objects in flow sequence using condenseFlow: true', function () {
+test('should not emit spaces between key: value and quote keys using condenseFlow: true', function () {
+  var object = { a: { b: 'c' } };
+  var objectDump = yaml.dump(object, { flowLevel: 0, indent: 0, condenseFlow: true });
   assert.equal(
-    yaml.dump({ a: { b: 'c' } }, { flowLevel: 0, indent: 0, condenseFlow: true }),
-    '{a:{b:c}}\n'
+    objectDump,
+    '{"a":{"b":c}}\n'
   );
+  assert.deepEqual(yaml.load(objectDump), object);
 });
diff --git a/test/issues/0369.js b/test/issues/0369.js
new file mode 100644
index 0000000..f96baac
--- /dev/null
+++ b/test/issues/0369.js
@@ -0,0 +1,11 @@
+'use strict';
+
+
+var assert = require('assert');
+var yaml = require('../../');
+
+
+test('should dump astrals as codepoint', function () {
+  assert.deepEqual(yaml.safeDump('😀'), '"\\U0001F600"\n');
+  assert.deepEqual(yaml.safeLoad('"\\U0001F600"'), '😀');
+});

-- 
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