Comments (6)
I bet it’s how carriage return/line feeds are normalized that is causing the problem. And because the get normalized the tab character gets counted as white space and the subsequently dropped. Unfortunately I don’t have time at this moment to debug and get a fix in, the parser is pretty complicated. I’ll hunt down where it’s at and post a link though.
from yamldotnet.
Basically it checks for any of those characters and counts it as a new line.
from yamldotnet.
I sse you actually have this test:
[Theory]
[InlineData("|\n b-carriage-return\r lll", "b-carriage-return\nlll")]
public void NewLinesAreParsedAccordingToTheSpecification(string yaml, string expected)
{
AssertSequenceOfEventsFrom(Yaml.ParserForText(yaml),
StreamStart,
DocumentStart(Implicit),
LiteralScalar(expected),
DocumentEnd(Implicit),
StreamEnd);
}
(other test cases removed)
It seems that maybe this is intended behavior? I'll check the spec.
I got this string from another spec that I'm trying to implement. It's possible they're just using bad YAML.
from yamldotnet.
@gregsdennis linked to https://yaml.org/spec/1.2.2/#54-line-break-characters in json-e/json-e#476. That section is about parsing, or perhaps more accurately tokenizing. It says that 0a0d
, 0a
, and 0d
should be normalized to some single newline format when seen i the input -- even when within a scalar such as a multiline string value.
However, that section doesn't address parsing escapes in a string value (I'm sure that's covered elsewhere). And more to the point, it doesn't describe anything after the tokenization is complete. So if by whatever means a YAML input parses to a string containing ASCII characters CR, LF, or a consecutive CR and LF, this section does not at all apply to handling of that string value as the parsing is complete.
I suspect that the error in this bug report is in the input:
var yaml = Parse("\" \f\n\r\t\vabc \f\n\r\t\v\""); // problem is here
the C# parser is interpreting those escapes, so YAML is getting actual FF, CR, LF, TAB, etc. characters. I suspect that should be
var yaml = Parse("\" \\f\\n\\r\\t\\vabc \\f\\n\\r\\t\\v\""); // problem is here
from yamldotnet.
The actual text in question is found in a YAML file and is:
template: {$eval: "rstrip(' \f\n\r\t\vabc \f\n\r\t\v')"}
To my understanding, this is decoded as the actual whitespace chars.
https://yaml-online-parser.appspot.com/ converts this to JSON as:
{
"template": {
"$eval": "rstrip(' \f\n\r\t\u000babc \f\n\r\t\u000b')"
}
}
which clearly preserves the characters.
Updating the test code above with (note the verbatim string @""
so escapes are right):
var json = JsonNode.Parse(@"{
""template"": {
""$eval"": ""rstrip(' \f\n\r\t\u000babc \f\n\r\t\u000b')""
}
}");
Console.WriteLine(JsonSerializer.Serialize(json, new JsonSerializerOptions{Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping}));
the output for this is:
{"template":{"$eval":"rstrip(' \f\n\r\t\u000Babc \f\n\r\t\u000B')"}}
from yamldotnet.
I sorted this out by just not using the parser for reading these strings. Might still be an issue, but I'll close for now. If it comes up again, surely someone will report it again.
from yamldotnet.
Related Issues (20)
- Invalid date format used in serialized JSON HOT 2
- YamlDotNet does not write accurately equal to yaml being loaded HOT 1
- JsonCompatible serializer is not Json compatible HOT 4
- Is the IDeserializer thread safe? HOT 2
- Update benchmark file
- 15.1.0 EnsureRoundTrip no longer works without tag mapping and protected default constructors HOT 4
- yamldotnet is missing NuGet package README file
- Json Compatible Serialization does not produce JSON for nodes.
- Including (parts of) another YAML file HOT 12
- Serilizing an object with tags similar to AWS Cloudformation HOT 4
- FSharp deserialization of records with optional record fields HOT 3
- Overriding the name of a type dynamically HOT 2
- ObjectNodeDeserializer: Naming Convention Error on Deserialization HOT 2
- is it possible to style a string in a special way? HOT 3
- Set license expression on nuget package HOT 1
- Improve nuget package readme HOT 2
- Serialization / deserialization is not thread safe HOT 2
- Very large files fail to parse HOT 6
- Using ```YamlStream``` will cause "property not found" in ```IDeserializer.Deserialize()``` HOT 1
- Empty line in comments HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yamldotnet.