diff --git a/CHANGELOG.md b/CHANGELOG.md index 6359d97..2dfac86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.1.5 + +* Fix a bug with 2.1.4 where source span information was being discarded for + scalar values. + ## 2.1.4 * Substantially improve performance. diff --git a/lib/src/yaml_node.dart b/lib/src/yaml_node.dart index d4961bb..99f7515 100644 --- a/lib/src/yaml_node.dart +++ b/lib/src/yaml_node.dart @@ -166,7 +166,7 @@ class YamlScalar extends YamlNode { /// Users of the library should not use this constructor. YamlScalar.internal(this.value, ScalarEvent scalar) : style = scalar.style { - _span = span; + _span = scalar.span; } /// Users of the library should not use this constructor. diff --git a/pubspec.yaml b/pubspec.yaml index f6a5b1e..f91d9cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: yaml -version: 2.1.4 +version: 2.1.5 author: "Dart Team " homepage: https://github.com/dart-lang/yaml description: A parser for YAML. diff --git a/test/yaml_test.dart b/test/yaml_test.dart index 8091dc5..c4601d5 100644 --- a/test/yaml_test.dart +++ b/test/yaml_test.dart @@ -54,6 +54,43 @@ main() { }); }); + test("includes source span information", () { + var yaml = loadYamlNode(r""" +- foo: + bar +- 123 +"""); + + expect(yaml.span.start.line, equals(0)); + expect(yaml.span.start.column, equals(0)); + expect(yaml.span.end.line, equals(3)); + expect(yaml.span.end.column, equals(0)); + + var map = yaml.nodes.first; + expect(map.span.start.line, equals(0)); + expect(map.span.start.column, equals(2)); + expect(map.span.end.line, equals(2)); + expect(map.span.end.column, equals(0)); + + var key = map.nodes.keys.first; + expect(key.span.start.line, equals(0)); + expect(key.span.start.column, equals(2)); + expect(key.span.end.line, equals(0)); + expect(key.span.end.column, equals(5)); + + var value = map.nodes.values.first; + expect(value.span.start.line, equals(1)); + expect(value.span.start.column, equals(4)); + expect(value.span.end.line, equals(1)); + expect(value.span.end.column, equals(7)); + + var scalar = yaml.nodes.last; + expect(scalar.span.start.line, equals(2)); + expect(scalar.span.start.column, equals(2)); + expect(scalar.span.end.line, equals(2)); + expect(scalar.span.end.column, equals(5)); + }); + // The following tests are all taken directly from the YAML spec // (http://www.yaml.org/spec/1.2/spec.html). Most of them are code examples // that are directly included in the spec, but additional tests are derived