yaml 2.4.1 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,6 +28,12 @@ npm install yaml
28
28
 
29
29
  **Note:** These docs are for `yaml@2`. For v1, see the [v1.10.0 tag](https://github.com/eemeli/yaml/tree/v1.10.0) for the source and [eemeli.org/yaml/v1](https://eemeli.org/yaml/v1/) for the documentation.
30
30
 
31
+ The development and maintenance of this library is [sponsored](https://github.com/sponsors/eemeli) by:
32
+
33
+ <a href="https://www.scipress.io/">
34
+ <img width=150 src="https://eemeli.org/yaml/images/scipress.svg" alt="Scipress" />
35
+ </a>
36
+
31
37
  ## API Overview
32
38
 
33
39
  The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/yaml/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the underlying [Lexer/Parser/Composer](https://eemeli.org/yaml/#parsing-yaml).
@@ -145,5 +151,5 @@ YAML.stringify({ number: 3, plain: 'string', block: 'two\nlines\n' })
145
151
  Browser testing provided by:
146
152
 
147
153
  <a href="https://www.browserstack.com/open-source">
148
- <img width=200 src="https://eemeli.org/yaml/images/browserstack.svg" />
154
+ <img width=200 src="https://eemeli.org/yaml/images/browserstack.svg" alt="BrowserStack" />
149
155
  </a>
@@ -149,6 +149,8 @@ class Lexer {
149
149
  */
150
150
  *lex(source, incomplete = false) {
151
151
  if (source) {
152
+ if (typeof source !== 'string')
153
+ throw TypeError('source is not a string');
152
154
  this.buffer = this.buffer ? this.buffer + source : source;
153
155
  this.lineEndPos = null;
154
156
  }
@@ -248,11 +250,16 @@ class Lexer {
248
250
  }
249
251
  if (line[0] === '%') {
250
252
  let dirEnd = line.length;
251
- const cs = line.indexOf('#');
252
- if (cs !== -1) {
253
+ let cs = line.indexOf('#');
254
+ while (cs !== -1) {
253
255
  const ch = line[cs - 1];
254
- if (ch === ' ' || ch === '\t')
256
+ if (ch === ' ' || ch === '\t') {
255
257
  dirEnd = cs - 1;
258
+ break;
259
+ }
260
+ else {
261
+ cs = line.indexOf('#', cs + 1);
262
+ }
256
263
  }
257
264
  while (true) {
258
265
  const ch = line[dirEnd - 1];
@@ -5,7 +5,7 @@ const floatNaN = {
5
5
  identify: value => typeof value === 'number',
6
6
  default: true,
7
7
  tag: 'tag:yaml.org,2002:float',
8
- test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
8
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
9
9
  resolve: str => str.slice(-3).toLowerCase() === 'nan'
10
10
  ? NaN
11
11
  : str[0] === '-'
@@ -18,7 +18,7 @@ const falseTag = {
18
18
  identify: value => value === false,
19
19
  default: true,
20
20
  tag: 'tag:yaml.org,2002:bool',
21
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
21
+ test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
22
22
  resolve: () => new Scalar(false),
23
23
  stringify: boolStringify
24
24
  };
@@ -5,7 +5,7 @@ const floatNaN = {
5
5
  identify: value => typeof value === 'number',
6
6
  default: true,
7
7
  tag: 'tag:yaml.org,2002:float',
8
- test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
8
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
9
9
  resolve: (str) => str.slice(-3).toLowerCase() === 'nan'
10
10
  ? NaN
11
11
  : str[0] === '-'
@@ -10,7 +10,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
10
10
  if (keyComment) {
11
11
  throw new Error('With simple keys, key nodes cannot have comments');
12
12
  }
13
- if (isCollection(key)) {
13
+ if (isCollection(key) || (!isNode(key) && typeof key === 'object')) {
14
14
  const msg = 'With simple keys, collection cannot be used as a key value';
15
15
  throw new Error(msg);
16
16
  }
@@ -151,6 +151,8 @@ class Lexer {
151
151
  */
152
152
  *lex(source, incomplete = false) {
153
153
  if (source) {
154
+ if (typeof source !== 'string')
155
+ throw TypeError('source is not a string');
154
156
  this.buffer = this.buffer ? this.buffer + source : source;
155
157
  this.lineEndPos = null;
156
158
  }
@@ -250,11 +252,16 @@ class Lexer {
250
252
  }
251
253
  if (line[0] === '%') {
252
254
  let dirEnd = line.length;
253
- const cs = line.indexOf('#');
254
- if (cs !== -1) {
255
+ let cs = line.indexOf('#');
256
+ while (cs !== -1) {
255
257
  const ch = line[cs - 1];
256
- if (ch === ' ' || ch === '\t')
258
+ if (ch === ' ' || ch === '\t') {
257
259
  dirEnd = cs - 1;
260
+ break;
261
+ }
262
+ else {
263
+ cs = line.indexOf('#', cs + 1);
264
+ }
258
265
  }
259
266
  while (true) {
260
267
  const ch = line[dirEnd - 1];
@@ -7,7 +7,7 @@ const floatNaN = {
7
7
  identify: value => typeof value === 'number',
8
8
  default: true,
9
9
  tag: 'tag:yaml.org,2002:float',
10
- test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/,
10
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
11
11
  resolve: str => str.slice(-3).toLowerCase() === 'nan'
12
12
  ? NaN
13
13
  : str[0] === '-'
@@ -20,7 +20,7 @@ const falseTag = {
20
20
  identify: value => value === false,
21
21
  default: true,
22
22
  tag: 'tag:yaml.org,2002:bool',
23
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
23
+ test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
24
24
  resolve: () => new Scalar.Scalar(false),
25
25
  stringify: boolStringify
26
26
  };
@@ -7,7 +7,7 @@ const floatNaN = {
7
7
  identify: value => typeof value === 'number',
8
8
  default: true,
9
9
  tag: 'tag:yaml.org,2002:float',
10
- test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/,
10
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
11
11
  resolve: (str) => str.slice(-3).toLowerCase() === 'nan'
12
12
  ? NaN
13
13
  : str[0] === '-'
@@ -12,7 +12,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
12
12
  if (keyComment) {
13
13
  throw new Error('With simple keys, key nodes cannot have comments');
14
14
  }
15
- if (identity.isCollection(key)) {
15
+ if (identity.isCollection(key) || (!identity.isNode(key) && typeof key === 'object')) {
16
16
  const msg = 'With simple keys, collection cannot be used as a key value';
17
17
  throw new Error(msg);
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "repository": "github:eemeli/yaml",