Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single character string containing special characters causes SyntaxErrorException #269

Closed
akusei opened this issue Jul 18, 2017 · 4 comments
Assignees

Comments

@akusei
Copy link

akusei commented Jul 18, 2017

If you have a single character string with a special character (in my case an exclamation mark) YamlDotNet will throw a SyntaxErrorException.

commandPrefix: '!'
commandPrefix: "!"
commandPrefix: "\x21"
commandPrefix: !!str "!"

All of the above cause the exception when deserializing. Is this a bug or am I not understanding something about the YAML specification?

commandPrefix: "a!"

The above works correctly but that's because the exclamation mark is the 2nd character and not the 1st.

@aaubry
Copy link
Owner

aaubry commented Jul 18, 2017

This looks like a bug. I'll need some time to look into this. Could you send the full exception message, including the stack trace? Thanks

@akusei
Copy link
Author

akusei commented Jul 18, 2017

@aaubry

YamlDotNet.Core.SyntaxErrorException: (Line: 4, Col: 16, Idx: 88) - (Line: 4, Col: 17, Idx: 89): While parsing a tag, did not find expected tag URI.
at YamlDotNet.Core.Scanner.ScanTagUri(String head, Mark start)
at YamlDotNet.Core.Scanner.ScanTag()
at YamlDotNet.Core.Scanner.FetchTag()
at YamlDotNet.Core.Scanner.FetchNextToken()
at YamlDotNet.Core.Scanner.FetchMoreTokens()
at YamlDotNet.Core.Scanner.MoveNextWithoutConsuming()
at YamlDotNet.Core.Parser.GetCurrentToken()
at YamlDotNet.Core.Parser.ParseBlockMappingValue()
at YamlDotNet.Core.Parser.StateMachine()
at YamlDotNet.Core.Parser.MoveNext()
at YamlDotNet.Core.ParserExtensions.Allow[T](IParser parser)
at YamlDotNet.Core.ParserExtensions.Expect[T](IParser parser)
at YamlDotNet.Serialization.NodeDeserializers.ObjectNodeDeserializer.YamlDotNet.Serialization.INodeDeserializer.Deserialize(IParser parser, Type expectedType, Func`3 nestedObjectDeserializer, Object& value)
at YamlDotNet.Serialization.ValueDeserializers.NodeValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
at YamlDotNet.Serialization.ValueDeserializers.AliasValueDeserializer.DeserializeValue(IParser parser, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
at YamlDotNet.Serialization.Deserializer.Deserialize(IParser parser, Type type)
at YamlDotNet.Serialization.Deserializer.Deserialize[T](String input)

@aaubry aaubry self-assigned this Sep 28, 2017
@MaorDavidzon
Copy link

Any update?

@EdwardCooke
Copy link
Collaborator

I just tested this with the following code and it worked fine.

using YamlDotNet.Serialization;

var deserializer = new DeserializerBuilder()
    .Build();
var yamls = new string[]
{
    "commandPrefix: '!'",
    "commandPrefix: \"!\"",
    "commandPrefix: \"\x21\"",
    "commandPrefix: !!str \"!\"",
};
foreach (var yaml in yamls)
{
    var deserialized = deserializer.Deserialize<X>(yaml);
    Console.WriteLine(yaml + ":" + (deserialized.CommandPrefix ?? "NULL"));
}


public class X
{
    [YamlMember(Alias = "commandPrefix")]
    public string CommandPrefix { get; set; }
}

Results in:

commandPrefix: '!':!
commandPrefix: "!":!
commandPrefix: "!":!
commandPrefix: !!str "!":!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants