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

Switch to jsoncpp as our json library #1005

Merged
merged 33 commits into from
Jun 4, 2019
Merged

Conversation

zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented May 24, 2019

Summary of the Pull Request

Switch to using jsoncpp as our json library. This lets us pretty-print the json file by default, and lets users place comments in the json file.

PR Checklist

Detailed Description of the Pull Request / Additional comments

We will now only re-write the file when the actual logical structure of the json object changes, not only when the serialization changes.

Unfortunately, this will remove any existing ordering of profiles, and make the order random. We don't terribly care though, because when #754 lands, this will be less painful.

It also introduces a top-level globals object to hold all the global properties, including keybindings. Existing profiles should gracefully upgrade.

  * Load messages from the Resources.resw file
  * Display a message when we fail to parse the settings on an initial parse, or
    on a reload.
    * Unfortunately, the dialog is styled incorrectly when the app theme is
      opposite the system theme. This can result in the button being invisible.
…or-dialog

# Conflicts:
#	src/cascadia/CascadiaPackage/Resources/en-US/Resources.resw
# Conflicts:
#	src/cascadia/TerminalApp/App.cpp
  They're no longer ordered, which I hate, but we'll live with.
  Involves moving serialization out of AppKeyBindings, because all we have is a
  cppwinrt type, and Json::Value is not a cppwinrt type
# Conflicts:
#	src/cascadia/TerminalApp/App.cpp
#	src/cascadia/TerminalApp/App.h
#	src/cascadia/TerminalApp/AppKeyBindings.cpp
#	src/cascadia/TerminalApp/AppKeyBindings.h
#	src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp
#	src/cascadia/TerminalApp/ColorScheme.cpp
#	src/cascadia/TerminalApp/GlobalAppSettings.cpp
#	src/cascadia/TerminalApp/Profile.cpp
Copy link
Member Author

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am disappointed I can't block my own PR

dep/jsoncpp/README.md Show resolved Hide resolved
src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/Utils.cpp Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/AppKeyBindingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/CascadiaSettingsSerialization.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/ColorScheme.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/ColorScheme.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/ColorScheme.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/GlobalAppSettings.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/pch.h Outdated Show resolved Hide resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels May 24, 2019
@dlong11
Copy link

dlong11 commented May 25, 2019

@zadjii-msft Just a note about jsoncpp - Our open source scanners report two issues with version 1.8.4. (I think this is the version that you are using)

https://www.cvedetails.com/cve/CVE-2018-17850/
https://www.cvedetails.com/cve/CVE-2018-17851/

Another reference - https://tools.cisco.com/security/center/viewAlert.x?alertId=58971

Just fyi - I saw jsoncpp it rang a bell.

@DHowett-MSFT
Copy link
Contributor

Our open source scanners report two issues with version 1.8.4. (I think this is the version that you are using)
Just fyi - I saw jsoncpp it rang a bell.

Thanks for keeping an eye out, @dlong11! We'll evaluate these (and make sure our governance tool knows about them as well). Since we're not putting JSON on an RPC path right now, it might be at an acceptable level of risk... we'll have to think about that.

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label May 28, 2019
@miniksa
Copy link
Member

miniksa commented May 30, 2019

@zadjii-msft, you requested my review here but it already looks full of comments by @DHowett-MSFT and @adiviness that are probably sufficient so I'll move onto another one for now. Ping me if you really want me to look at this.

static constexpr std::wstring_view SCHEMES_KEY{ L"schemes" };
static constexpr std::string_view PROFILES_KEY{ "profiles" };
static constexpr std::string_view KEYBINDINGS_KEY{ "keybindings" };
static constexpr std::string_view GLOBALS_KEY{ "globals" };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is globals the right name for this? It's like application settings... but also, i dunno, why aren't they at root level?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frankly I just wanted to bundle them up. now that we lose the ordering we had before, the file would contain something like

{
  "global1": val, 
  "global2": val, 
  "profiles": [
     { ... },
     { ... },
  ],
  "global3": val,
  "colorSchemes": [
    { ... }
  ],
  "global4": val,
}

with the globals intermixed with things like the profiles, color schemes, etc, which I thought was annoying. I can switch it back if we want.

@zadjii-msft zadjii-msft added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels May 30, 2019
src/cascadia/TerminalApp/AppKeyBindingsSerialization.h Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/Profile.cpp Outdated Show resolved Hide resolved
src/cascadia/TerminalApp/Profile.cpp Outdated Show resolved Hide resolved
@zadjii-msft zadjii-msft requested review from DHowett-MSFT and adiviness and removed request for DHowett-MSFT May 31, 2019 13:33
@zadjii-msft
Copy link
Member Author

@DHowett-MSFT @miniksa can I get a second on this?

@DHowett-MSFT
Copy link
Contributor

Arg I thought I seconded. Sorry!

return { FileIO::ReadTextAsync(storageFile, UnicodeEncoding::Utf8).get() };
auto buffer = FileIO::ReadBufferAsync(storageFile).get();
auto bufferData = buffer.data();
std::vector<uint8_t> bytes{ bufferData, bufferData + buffer.Length() };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, do we need to make a copy into a vector and THEN a copy into a string?

@zadjii-msft
Copy link
Member Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to a JSON serializer that supports pretty printing
6 participants