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

diff() has issues with slashes in object keys #9

Closed
hinzundcode opened this issue Aug 24, 2019 · 2 comments
Closed

diff() has issues with slashes in object keys #9

hinzundcode opened this issue Aug 24, 2019 · 2 comments

Comments

@hinzundcode
Copy link

Great library, exactly what I needed! The only problem is I can't diff objects with keys containing slashes. The generated patch is invalid and can't be applied.

extern crate serde_json;
extern crate json_patch;
use serde_json::json;
use json_patch::{diff, patch};

fn main() {
	let mut json_a = json!({
		"/foo/bar": 1,
	});
	
	let json_b = json!({
		"/foo/bar": 2,
	});
	
	let p = diff(&json_a, &json_b);
	dbg!(&p);
	
	patch(&mut json_a, &p).unwrap();
	dbg!(&json_a);
}
[src/main.rs:16] &p = Patch(
    [
        Replace(
            ReplaceOperation {
                path: "//foo/bar",
                value: Number(
                    2,
                ),
            },
        ),
    ],
)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidPointer', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
idubrov added a commit that referenced this issue Aug 25, 2019
Need to escape characters `/` and `~` when generating paths for patch.

Closes #9
@idubrov
Copy link
Owner

idubrov commented Aug 25, 2019

Should be fixed in 0.2.6.

@hinzundcode
Copy link
Author

thank you!

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