Page MenuHomePhabricator

[clang] tooling replacements are escaped when exporting to YAML
Needs ReviewPublic

Authored by njames93 on Mar 11 2020, 6:11 PM.

Details

Summary

Escapes replacement text when exporting to yaml and unescapes when importing from yaml.

Diff Detail

Event Timeline

njames93 created this revision.Mar 11 2020, 6:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2020, 6:11 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
njames93 updated this revision to Diff 249856.Mar 12 2020, 2:04 AM
  • Moved escape/unescape impl to source file
njames93 updated this revision to Diff 249857.Mar 12 2020, 2:11 AM
  • Small tidy of code
njames93 updated this revision to Diff 249860.Mar 12 2020, 2:20 AM
  • Fix test case not being ran
njames93 marked an inline comment as done.Mar 12 2020, 2:22 AM
njames93 added inline comments.
clang/unittests/Tooling/ReplacementsYamlTest.cpp
68

Can this ever be false. Does execution of a test case stop once an ASSERT_EQ fails

njames93 updated this revision to Diff 249875.Mar 12 2020, 3:06 AM
  • Fix broken dependencies
Harbormaster completed remote builds in B48944: Diff 249857.
AlexanderLanin requested changes to this revision.Mar 12 2020, 11:26 AM
AlexanderLanin added inline comments.
clang/lib/Tooling/ReplacementsYaml.cpp
23

Just so I have asked ;-)
Escaping every \ would be incorrect? Basically duplicate every '\'.

clang/unittests/Tooling/ReplacementsYamlTest.cpp
55

I think it would be worthwhile to test other characters as well.
50% of that would be purely for documentation purposes. What would happen when you escape \x and unescape \\x?

68

Yes, assert stops the test case. After the assert you can safely assume they are identical.

76

I assume this kind of test would have been green even without your change? Or would it fail?
You are testing that it is reconstructed correctly (which is indeed the main point), but not the escaping and unescaping.
You should probably test a concrete example with(escaped text, expected escaped test).

This revision now requires changes to proceed.Mar 12 2020, 11:26 AM
njames93 updated this revision to Diff 250038.Mar 12 2020, 1:26 PM
  • Fix another broken dependency
njames93 updated this revision to Diff 250053.Mar 12 2020, 2:09 PM
njames93 marked 6 inline comments as done.
  • Extend tests
clang/lib/Tooling/ReplacementsYaml.cpp
23

You need to escape the escape character to avoid ambiguity when unescaping later

Say the code has the raw string which is \ followed by n. it would be escaped as \n.
Then when it comes to unescape it will read \n as a newline.
Escaping the \ leads to the output being \\n which will be read back as a \ followed by n.

clang/unittests/Tooling/ReplacementsYamlTest.cpp
55

I have added all the c++ escape characters apart from \' as that is handled in the yaml string parser anyway and \" as that seems to be ignore anyway

76

Yes this should've passed before however the issue was one more of readability. Things like the old double newline just look confusing whereas every programmer knows that '\n' is code for newline.
I have planned to add that in.

Fine for me. Fixes newline bug in https://bugs.llvm.org/show_bug.cgi?id=45150.
However I don't have "review privileges" here.

AlexanderLanin resigned from this revision.Mar 12 2020, 3:45 PM