зеркало из https://github.com/stride3d/SharpYaml.git
Fixed bug in Scanner.ScanTag() that prevented usage of local tags.
This commit is contained in:
Родитель
1a5aad7430
Коммит
2924665d2b
|
@ -100,7 +100,8 @@ namespace YamlDotNet.Core
|
|||
{
|
||||
switch (state)
|
||||
{
|
||||
case ParserState.YAML_PARSE_STREAM_START_STATE: return ParseStreamStart();
|
||||
case ParserState.YAML_PARSE_STREAM_START_STATE:
|
||||
return ParseStreamStart();
|
||||
|
||||
case ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE:
|
||||
return ParseDocumentStart(true);
|
||||
|
|
|
@ -307,11 +307,11 @@ namespace YamlDotNet.Core
|
|||
// Is it the document start indicator?
|
||||
|
||||
bool isDocumentStart =
|
||||
mark.Column == 0 &&
|
||||
analyzer.Check('-', 0) &&
|
||||
analyzer.Check('-', 1) &&
|
||||
analyzer.Check('-', 2) &&
|
||||
analyzer.IsBlankOrBreakOrZero(3);
|
||||
mark.Column == 0 &&
|
||||
analyzer.Check('-', 0) &&
|
||||
analyzer.Check('-', 1) &&
|
||||
analyzer.Check('-', 2) &&
|
||||
analyzer.IsBlankOrBreakOrZero(3);
|
||||
|
||||
if (isDocumentStart)
|
||||
{
|
||||
|
@ -322,11 +322,11 @@ namespace YamlDotNet.Core
|
|||
// Is it the document end indicator?
|
||||
|
||||
bool isDocumentEnd =
|
||||
mark.Column == 0 &&
|
||||
analyzer.Check('.', 0) &&
|
||||
analyzer.Check('.', 1) &&
|
||||
analyzer.Check('.', 2) &&
|
||||
analyzer.IsBlankOrBreakOrZero(3);
|
||||
mark.Column == 0 &&
|
||||
analyzer.Check('.', 0) &&
|
||||
analyzer.Check('.', 1) &&
|
||||
analyzer.Check('.', 2) &&
|
||||
analyzer.IsBlankOrBreakOrZero(3);
|
||||
|
||||
if (isDocumentEnd)
|
||||
{
|
||||
|
@ -476,9 +476,9 @@ namespace YamlDotNet.Core
|
|||
bool isInvalidPlainScalarCharacter = analyzer.IsBlankOrBreakOrZero() || analyzer.Check("-?:,[]{}#&*!|>'\"%@`");
|
||||
|
||||
bool isPlainScalar =
|
||||
!isInvalidPlainScalarCharacter ||
|
||||
(analyzer.Check('-') && !analyzer.IsBlank(1)) ||
|
||||
(flowLevel == 0 && (analyzer.Check("?:")) && !analyzer.IsBlankOrBreakOrZero(1));
|
||||
!isInvalidPlainScalarCharacter ||
|
||||
(analyzer.Check('-') && !analyzer.IsBlank(1)) ||
|
||||
(flowLevel == 0 && (analyzer.Check("?:")) && !analyzer.IsBlankOrBreakOrZero(1));
|
||||
|
||||
if (isPlainScalar)
|
||||
{
|
||||
|
@ -1250,9 +1250,7 @@ namespace YamlDotNet.Core
|
|||
{
|
||||
// It wasn't a handle after all. Scan the rest of the tag.
|
||||
|
||||
suffix = ScanTagUri(null, start);
|
||||
|
||||
ScanTagUri(firstPart, start);
|
||||
suffix = ScanTagUri(firstPart, start);
|
||||
|
||||
// Set the handle to '!'.
|
||||
|
||||
|
@ -2183,9 +2181,9 @@ namespace YamlDotNet.Core
|
|||
if (width == 0)
|
||||
{
|
||||
width = (octet & 0x80) == 0x00 ? 1 :
|
||||
(octet & 0xE0) == 0xC0 ? 2 :
|
||||
(octet & 0xF0) == 0xE0 ? 3 :
|
||||
(octet & 0xF8) == 0xF0 ? 4 : 0;
|
||||
(octet & 0xE0) == 0xC0 ? 2 :
|
||||
(octet & 0xF0) == 0xE0 ? 3 :
|
||||
(octet & 0xF8) == 0xF0 ? 4 : 0;
|
||||
|
||||
if (width == 0)
|
||||
{
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace YamlDotNet.UnitTests
|
|||
|
||||
private void AssertCurrent(Parser parser, ParsingEvent expected) {
|
||||
Console.WriteLine(expected.GetType().Name);
|
||||
Assert.IsTrue(expected.GetType().IsAssignableFrom(parser.Current.GetType()), "The event is not of the expected type.");
|
||||
Assert.IsTrue(expected.GetType().IsAssignableFrom(parser.Current.GetType()), string.Format("The event is not of the expected type. Exprected: {0}, Actual: {1}", expected.GetType().Name, parser.Current.GetType().Name));
|
||||
|
||||
foreach (var property in expected.GetType().GetProperties()) {
|
||||
if(property.PropertyType != typeof(Mark) && property.CanRead) {
|
||||
|
@ -388,5 +388,25 @@ namespace YamlDotNet.UnitTests
|
|||
AssertNext(parser, new StreamEnd());
|
||||
AssertDoesNotHaveNext(parser);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTokenWithLocalTags()
|
||||
{
|
||||
Parser parser = CreateParser("local-tags.yaml");
|
||||
|
||||
AssertNext(parser, new StreamStart());
|
||||
AssertNext(parser, new DocumentStart(null, defaultDirectives, false));
|
||||
AssertNext(parser, new MappingStart(null, "!MyObject", false, MappingStyle.Block));
|
||||
AssertNext(parser, new Scalar(null, null, "a", ScalarStyle.Plain, true, false));
|
||||
AssertNext(parser, new Scalar(null, null, "1.0", ScalarStyle.Plain, true, false));
|
||||
AssertNext(parser, new Scalar(null, null, "b", ScalarStyle.Plain, true, false));
|
||||
AssertNext(parser, new Scalar(null, null, "42", ScalarStyle.Plain, true, false));
|
||||
AssertNext(parser, new Scalar(null, null, "c", ScalarStyle.Plain, true, false));
|
||||
AssertNext(parser, new Scalar(null, null, "-7", ScalarStyle.Plain, true, false));
|
||||
AssertNext(parser, new MappingEnd());
|
||||
AssertNext(parser, new DocumentEnd(true));
|
||||
AssertNext(parser, new StreamEnd());
|
||||
AssertDoesNotHaveNext(parser);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace YamlDotNet.UnitTests.RepresentationModel
|
||||
{
|
||||
[TestClass]
|
||||
public class Program
|
||||
{
|
||||
[TestMethod]
|
||||
public void LoadYamlStream()
|
||||
{
|
||||
// Setup the input
|
||||
var input = new StringReader(Document);
|
||||
|
||||
// Load the stream
|
||||
var yaml = new YamlStream();
|
||||
yaml.Load(input);
|
||||
|
||||
// Examine the stream
|
||||
var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;
|
||||
|
||||
foreach (var entry in mapping.Children)
|
||||
{
|
||||
Console.WriteLine(((YamlScalarNode)entry.Key).Value);
|
||||
}
|
||||
}
|
||||
|
||||
private const string Document = @"---
|
||||
receipt: Oz-Ware Purchase Invoice
|
||||
date: 2007-08-06
|
||||
customer:
|
||||
given: Dorothy
|
||||
family: Gale
|
||||
|
||||
items:
|
||||
- part_no: A4786
|
||||
descrip: Water Bucket (Filled)
|
||||
price: 1.47
|
||||
quantity: 4
|
||||
|
||||
- part_no: E1628
|
||||
descrip: High Heeled ""Ruby"" Slippers
|
||||
price: 100.27
|
||||
quantity: 1
|
||||
|
||||
bill-to: &id001
|
||||
street: |
|
||||
123 Tornado Alley
|
||||
Suite 16
|
||||
city: East Westville
|
||||
state: KS
|
||||
|
||||
ship-to: *id001
|
||||
|
||||
specialDelivery: >
|
||||
Follow the Yellow Brick
|
||||
Road to the Emerald City.
|
||||
Pay no attention to the
|
||||
man behind the curtain.
|
||||
...";
|
||||
}
|
||||
}
|
|
@ -208,10 +208,10 @@ namespace YamlDotNet.UnitTests.RepresentationModel
|
|||
{
|
||||
Y original = new Y();
|
||||
original.Child = new Y
|
||||
{
|
||||
Child = original,
|
||||
Child2 = original
|
||||
};
|
||||
{
|
||||
Child = original,
|
||||
Child2 = original
|
||||
};
|
||||
|
||||
serializer.Serialize(buffer, original);
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
<Compile Include="Core\ScannerTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RepresentationModel\ObjectConverterTests.cs" />
|
||||
<Compile Include="RepresentationModel\Samples.cs" />
|
||||
<Compile Include="RepresentationModel\SerializationTests.cs" />
|
||||
<Compile Include="RepresentationModel\YamlStreamTests.cs" />
|
||||
<Compile Include="Runner.cs" />
|
||||
|
@ -161,6 +162,9 @@
|
|||
<ItemGroup>
|
||||
<EmbeddedResource Include="invalid-reference.yaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="local-tags.yaml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
--- !MyObject
|
||||
a: 1.0
|
||||
b: 42
|
||||
c: -7
|
Загрузка…
Ссылка в новой задаче