# HG changeset patch # User Kim Alvefur # Date 1652026001 -7200 # Node ID 83f269db68503784184f01c085c7d0ee4b88e746 # Parent 65316782862f61f38d09c0d5689b057f17451afc# Parent 87c3d45208efcbafde8d4ecc7d8d53eb5175f95f Merge 0.12->trunk diff -r 65316782862f -r 83f269db6850 spec/util_jsonpointer_spec.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/spec/util_jsonpointer_spec.lua Sun May 08 18:06:41 2022 +0200 @@ -0,0 +1,38 @@ +describe("util.jsonpointer", function() + local json, jp; + setup(function() + json = require "util.json"; + jp = require "util.jsonpointer"; + end) + describe("resolve()", function() + local example; + setup(function() + example = json.decode([[{ + "foo": ["bar", "baz"], + "": 0, + "a/b": 1, + "c%d": 2, + "e^f": 3, + "g|h": 4, + "i\\j": 5, + "k\"l": 6, + " ": 7, + "m~n": 8 + }]]) + end) + it("works", function() + assert.same(example, jp.resolve(example, "")); + assert.same({ "bar", "baz" }, jp.resolve(example, "/foo")); + assert.same("bar", jp.resolve(example, "/foo/0")); + assert.same(0, jp.resolve(example, "/")); + assert.same(1, jp.resolve(example, "/a~1b")); + assert.same(2, jp.resolve(example, "/c%d")); + assert.same(3, jp.resolve(example, "/e^f")); + assert.same(4, jp.resolve(example, "/g|h")); + assert.same(5, jp.resolve(example, "/i\\j")); + assert.same(6, jp.resolve(example, "/k\"l")); + assert.same(7, jp.resolve(example, "/ ")); + assert.same(8, jp.resolve(example, "/m~0n")); + end) + end) +end) diff -r 65316782862f -r 83f269db6850 teal-src/util/jsonpointer.tl --- a/teal-src/util/jsonpointer.tl Sat May 07 13:10:27 2022 +0200 +++ b/teal-src/util/jsonpointer.tl Sun May 08 18:06:41 2022 +0200 @@ -24,7 +24,7 @@ elseif idx is integer then local i = tonumber(token) if token == "-" then i = #ref + 1 end - new_ref = ref[i] + new_ref = ref[i+1] else return nil, "invalid-table" end diff -r 65316782862f -r 83f269db6850 util/jsonpointer.lua --- a/util/jsonpointer.lua Sat May 07 13:10:27 2022 +0200 +++ b/util/jsonpointer.lua Sun May 08 18:06:41 2022 +0200 @@ -20,7 +20,7 @@ if token == "-" then i = #ref + 1 end - new_ref = ref[i] + new_ref = ref[i + 1] else return nil, "invalid-table" end