Skip Menu |
 

This queue is for tickets about the JSON-Path CPAN distribution.

Report information
The Basics
Id: 83249
Status: resolved
Priority: 0/
Queue: JSON-Path

People
Owner: perl [...] toby.ink
Requestors: m.nacamura [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.203
Fixed in: (no value)



Subject: Problem with JSON::Path::set
Download (untitled) / with headers
text/plain 1.2k
JSON::Path::set does not work correctly when using JSON paths such as '$.store.book[2].author', which does not include wildcards (i.e., '*'). I added an additional test (please find the attached file) for checking JSON::Path::set and obtained failures as follows: ============================== % make test cp lib/JSON/Path.pm blib/lib/JSON/Path.pm PERL_DL_NONLAZY=1 /opt/local/bin/perl5.16 "-MExtUtils::Command::MM" "-e" "test_harness(0, 'inc', 'blib/lib', 'blib/arch')" t/01basic.t t/02zeroth.t t/03shortcuts.t t/04map.t t/05set.t t/01basic.t ...... ok t/02zeroth.t ..... ok t/03shortcuts.t .. ok t/04map.t ........ ok t/05set.t ........ 1/? # Failed test at t/05set.t line 81. # got: 'Herman Melville' # expected: 'Anon' # Looks like you failed 1 test of 6. t/05set.t ........ Dubious, test returned 1 (wstat 256, 0x100) Failed 2/6 subtests Test Summary Report ------------------- t/05set.t (Wstat: 256 Tests: 5 Failed: 1) Failed test: 6 Non-zero exit status: 1 Parse errors: Tests out of sequence. Found (6) but expected (5) Bad plan. You planned 6 tests but ran 5. Files=5, Tests=27, 1 wallclock secs ( 0.05 usr 0.02 sys + 0.43 cusr 0.06 csys = 0.56 CPU) Result: FAIL Failed 1/5 test programs. 1/27 subtests failed. ==============================
Subject: 05set.t
Download 05set.t
text/x-perl 1.3k
use Test::More; use JSON::Path -all; use JSON; my $object = from_json(<<'JSON'); { "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": { "color": "red", "price": 19.95 } } } JSON my $titles = '$.store.book[*].title'; my $jpath = JSON::Path->new ($titles); is_deeply( [ $jpath->values($object) ], [ "Sayings of the Century", "Sword of Honour", "Moby Dick", "The Lord of the Rings" ] ); is( $jpath->set($object => 'TBD', 2), 2, ); is_deeply( [ $jpath->values($object) ], [ "TBD", "TBD", "Moby Dick", "The Lord of the Rings" ] ); my $author = '$.store.book[2].author'; $jpath = JSON::Path->new ($author); is( $jpath->value($object), "Herman Melville", ); is( $jpath->set($object => 'Anon'), 1, ); is( $jpath->value($object), 'Anon', ); done_testing();
Download (untitled) / with headers
text/plain 296b
This looks like a good test case. I've known there were problems with the setter, but hadn't been quite able to pin them down - this should help. Unless you say otherwise, I'm going to assume that I have your permission to include this test case in the test suite of future JSON-Path versions.
Download (untitled) / with headers
text/plain 196b
OK, I've checked a fix for this issue into the repository https://bitbucket.org/tobyink/p5-json-path/ commits/277a16901cf6fc4df3d67daa030381b9 I'll upload a release to CPAN in the next few days.
Subject: Re: [rt.cpan.org #83249] Problem with JSON::Path::set
Date: Wed, 13 Feb 2013 12:46:43 +0900
To: bug-JSON-Path [...] rt.cpan.org
From: Mitsuhiro Nakamura <m.nacamura [...] gmail.com>
Download (untitled) / with headers
text/plain 400b
Many thanks for your rapid fix. It works now fine. On Wednesday, February 13, 2013 at 5:41 AM, Toby Inkster via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=83249 > > > OK, I've checked a fix for this issue into the repository > > https://bitbucket.org/tobyink/p5-json-path/ > commits/277a16901cf6fc4df3d67daa030381b9 > > I'll upload a release to CPAN in the next few days.
Fixed in 0.204.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.