# settings_json: Locate a key by its own range, not by scanning quotes \(\#62949\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/510a624ae1b437a3402d3cac7f9ddea80b6a6327)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 510a624ae1b437a3402d3cac7f9ddea80b6a6327

Requested commit: 510a624ae1b437a3402d3cac7f9ddea80b6a6327

Commit: 510a624ae1b437a3402d3cac7f9ddea80b6a6327

Tree: c06d4f79493a5ef7169d51aa5ae28ef939cdd401

Author: Vlad Gaevsky

Committer: GitHub

## Message

```
settings_json: Locate a key by its own range, not by scanning quotes (#62949)

`replace_value_in_json_text` spelled a newly inserted key with
hand-written quotes, so a key carrying a `"` or a `\` produced invalid
JSON. The removal and rename paths then could not find such a key again:
both walked backwards to the nearest raw `"`, which lands inside an
escape, and ate the neighbouring entry while leaving JSON that still
parses.

The parser already hands back the key's byte range, so the three sites
use it, and serde for the spelling, the way key lookup and the
nested-construction path always did.

Worth knowing beyond the escaping: `update_value_in_json_text` pushes
every map key into the key path verbatim, so any settings map whose keys
are not authored by hand reaches this. Most are typed by the user, but
`favorite_config_option_values` is keyed by a `SessionConfigId` that an
ACP agent supplies over the protocol.

Tests cover insertion into a single-line and a multi-line object,
removal and rename, all with a key carrying a quote and a backslash.

Release Notes:

- Fixed a settings key containing a quote or a backslash corrupting
`settings.json`.
```

## Parents

- [ba6b83f89d5d7a6f02cd07dea3501d935f77fee0](https://git.cafe/gitcafe/zed/commit/ba6b83f89d5d7a6f02cd07dea3501d935f77fee0?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/510a624ae1b437a3402d3cac7f9ddea80b6a6327?format=markdown)
