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

Newline and carriage return control characters characters are not escaped when converting YAML to JSON #56

Open
dawu415 opened this issue Aug 13, 2019 · 1 comment

Comments

@dawu415
Copy link

dawu415 commented Aug 13, 2019

Currently, control characters such as newlines and carriage returns are not escaped and passed through.

e.g.
When one inputs the following byte data into YAMLToJSON()

{"name": "-----BEGIN CERTIFICATE-----
MIIC3aaaaaaaDAwMQswCQYDVQQGxxxxxxxsjlsdkfjsdlkfjsdlkjsdvlskdEwJB
VTENMAsGA1UECwwEZGF3dTESMBAGA1UEAwwJKi5kYXd1LmlvMB4XDTE5MDYwNjAz
MTEzNVoXDTIwMDYwNTAzMTEzNVowMDELMAkGA1UEBhMCQVUxDTALBgNVBAsMBGRh
d3UxEjAQBgNVBAMMCSouZGF3dS5pbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBANBuhemwaaaaaaaaaaaaaaaaaaajCj+Yo20QhidabJ8SgrrSFJEz/btm
UQATAqLXOczhIqxJzIOIhW2klI4JQTkR96FZkqCOktKtQNjXrL+5L2Jb7ouHLak7
8j3HjhCmmfgh7MZ1wq7O+MUyDCEHI5ixd8eC8TEr1XgCJyhqlYestsWhvGUP8gth
DGgFHMBOx033RvVkTbJcagSspMsQZ/sCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEA
bocw2bBJfb2uvK0Ej5PpTQPBnynVsJxBvCJlSAqA7Mk9NieRSbdj7Ul+nRViSwER
41bTogRS4mhl3qaLGThB4DlsS/wqRp5ocTqBMWkCssEdCWwkJVWZxPQ42Kh5uXYY
9JsEudPLv0hh+b5Oyoi7f2asljasflkasjflkGSqEJH2xauwfZnKTjeb/tmtqtoi
coL/1owTdHspg59SQYUBJUPlc0Ids6OolsmOnO9icwJ7c1AIkpKps4mL9XgxCtD7
BVRmQ5RwTOlBLAmpU7R1gg==
-----END CERTIFICATE-----", "age": 30}

the byte output is the following

{"age":30,"name":"-----BEGIN CERTIFICATE----- MIIC3aaaaaaaDAwMQswCQYDVQQGxxxxxxxsjlsdkfjsdlkfjsdlkjsdvlskdEwJB VTENMAsGA1UECwwEZGF3dTESMBAGA1UEAwwJKi5kYXd1LmlvMB4XDTE5MDYwNjAz MTEzNVoXDTIwMDYwNTAzMTEzNVowMDELMAkGA1UEBhMCQVUxDTALBgNVBAsMBGRh d3UxEjAQBgNVBAMMCSouZGF3dS5pbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC AQoCggEBANBuhemwaaaaaaaaaaaaaaaaaaajCj+Yo20QhidabJ8SgrrSFJEz/btm UQATAqLXOczhIqxJzIOIhW2klI4JQTkR96FZkqCOktKtQNjXrL+5L2Jb7ouHLak7 8j3HjhCmmfgh7MZ1wq7O+MUyDCEHI5ixd8eC8TEr1XgCJyhqlYestsWhvGUP8gth DGgFHMBOx033RvVkTbJcagSspMsQZ/sCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEA bocw2bBJfb2uvK0Ej5PpTQPBnynVsJxBvCJlSAqA7Mk9NieRSbdj7Ul+nRViSwER 41bTogRS4mhl3qaLGThB4DlsS/wqRp5ocTqBMWkCssEdCWwkJVWZxPQ42Kh5uXYY 9JsEudPLv0hh+b5Oyoi7f2asljasflkasjflkGSqEJH2xauwfZnKTjeb/tmtqtoi coL/1owTdHspg59SQYUBJUPlc0Ids6OolsmOnO9icwJ7c1AIkpKps4mL9XgxCtD7 BVRmQ5RwTOlBLAmpU7R1gg== -----END CERTIFICATE-----"}

An example of this can be found at this playground
https://play.golang.org/p/1SFyCUgmMBN

It would be nice if newline and carriage return characters can be escaped after running YAMLToJSON()
i.e.,

{"age": 30, "name": "-----BEGIN CERTIFICATE-----\nMIIC3aaaaaaaDAwMQswCQYDVQQGxxxxxxxsjlsdkfjsdlkfjsdlkjsdvlskdEwJB\nVTENMAsGA1UECwwEZGF3dTESMBAGA1UEAwwJKi5kYXd1LmlvMB4XDTE5MDYwNjAz\nMTEzNVoXDTIwMDYwNTAzMTEzNVowMDELMAkGA1UEBhMCQVUxDTALBgNVBAsMBGRh\nd3UxEjAQBgNVBAMMCSouZGF3dS5pbzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\nAQoCggEBANBuhemwaaaaaaaaaaaaaaaaaaajCj+Yo20QhidabJ8SgrrSFJEz/btm\nUQATAqLXOczhIqxJzIOIhW2klI4JQTkR96FZkqCOktKtQNjXrL+5L2Jb7ouHLak7\n8j3HjhCmmfgh7MZ1wq7O+MUyDCEHI5ixd8eC8TEr1XgCJyhqlYestsWhvGUP8gth\nDGgFHMBOx033RvVkTbJcagSspMsQZ/sCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEA\nbocw2bBJfb2uvK0Ej5PpTQPBnynVsJxBvCJlSAqA7Mk9NieRSbdj7Ul+nRViSwER\n41bTogRS4mhl3qaLGThB4DlsS/wqRp5ocTqBMWkCssEdCWwkJVWZxPQ42Kh5uXYY\n9JsEudPLv0hh+b5Oyoi7f2asljasflkasjflkGSqEJH2xauwfZnKTjeb/tmtqtoi\ncoL/1owTdHspg59SQYUBJUPlc0Ids6OolsmOnO9icwJ7c1AIkpKps4mL9XgxCtD7\nBVRmQ5RwTOlBLAmpU7R1gg==\n-----END CERTIFICATE-----"}
@guoziyi-study
Copy link

这个问题还没有得到解决吗?我也想保留yaml的换行和被注释的内容

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

2 participants