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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation gives incorrect advice for making patches RFC-6902 compliant #1051

Open
3 tasks done
uckelman opened this issue Jun 11, 2023 · 0 comments
Open
3 tasks done

Comments

@uckelman
Copy link

uckelman commented Jun 11, 2023

馃悰 Bug Report

The patches documentation says

The generated patches are similar (but not the same) to the RFC-6902 JSON patch standard, except that the path property is an array, rather than a string. This makes processing patches easier. If you want to normalize to the official specification, patch.path = patch.path.join("/") should do the trick.

The advice for making the patches RFC-6920 compliant is incorrect. The suggested adjustment, patch.path.join("/"), will never return a path string with a leading /.

RFC-6902 requires the path to be a JSON Pointer, defined in RFC-6901. The grammar in RFC-6901 搂3 defines a json-pointer token as follows:

 json-pointer    = *( "/" reference-token )

Thus, the only json-pointer which does not start with / is the empty string.

The suggestion in the docs produces non-compliant paths such as a/b/c (instead of /a/b/c).

Link to repro

See next section.

To Reproduce

const path = ['a'];
console.log(path.join("/"));

Observed behavior

a

Expected behavior

/a

Obviously we don't expect join() to produce this, but rather we expect the docs to suggest code which would.

Environment

Any environment you want---this is how join() works.

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
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

1 participant