Skip to content

Commit 75b95e9

Browse files
Merge pull request #264 from jacobwilliams/get-path-fix
Get path fix
2 parents 59d1fa1 + 35396d2 commit 75b95e9

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/json_value_module.F90

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5577,9 +5577,6 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
55775577
logical(LK) :: use_brackets !! to use '[]' characters for arrays
55785578
logical(LK) :: parent_is_root !! if the parent is the root
55795579

5580-
!initialize:
5581-
path = CK_''
5582-
55835580
!optional input:
55845581
if (present(use_alt_array_tokens)) then
55855582
use_brackets = .not. use_alt_array_tokens
@@ -5597,13 +5594,19 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
55975594

55985595
!get info about the current variable:
55995596
call json%info(tmp,name=name)
5597+
if (json%path_mode==2) then
5598+
name = encode_rfc6901(name)
5599+
end if
56005600

56015601
! if tmp a child of an object, or an element of an array
56025602
if (associated(tmp%parent)) then
56035603

56045604
!get info about the parent:
56055605
call json%info(tmp%parent,var_type=var_type,&
56065606
n_children=n_children,name=parent_name)
5607+
if (json%path_mode==2) then
5608+
parent_name = encode_rfc6901(parent_name)
5609+
end if
56075610

56085611
select case (var_type)
56095612
case (json_array)
@@ -5680,7 +5683,7 @@ subroutine json_get_path(json, p, path, found, use_alt_array_tokens, path_sep)
56805683
end if
56815684

56825685
!for errors, return blank string:
5683-
if (json%exception_thrown) then
5686+
if (json%exception_thrown .or. .not. allocated(path)) then
56845687
path = CK_''
56855688
else
56865689
if (json%path_mode==2) then
@@ -5712,14 +5715,14 @@ subroutine add_to_path(str,path_sep)
57125715
select case (json%path_mode)
57135716
case(2)
57145717
! in this case, the options are ignored
5715-
if (path==CK_'') then
5718+
if (.not. allocated(path)) then
57165719
path = str
57175720
else
57185721
path = str//slash//path
57195722
end if
57205723
case(1)
57215724
! default path format
5722-
if (path==CK_'') then
5725+
if (.not. allocated(path)) then
57235726
path = str
57245727
else
57255728
if (present(path_sep)) then

src/tests/jf_test_23.f90

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ subroutine test_23(error_cnt)
3232
real(wp) :: rval
3333
logical :: found
3434
character(kind=json_CK,len=10),dimension(:),allocatable :: cval_array
35+
integer :: i !! counter
3536

3637
error_cnt = 0
3738
call json%initialize( trailing_spaces_significant=.true.,&
@@ -220,20 +221,27 @@ subroutine test_23(error_cnt)
220221
path_mode=2) ! RFC6901 paths
221222

222223
write(error_unit,'(A)') ''
223-
key = '/data/1/real'
224-
call json%get(key,p)
225-
call core%get_path(p, path, found)
226-
if (found) then
227-
if (key==path) then
228-
write(error_unit,'(A)') 'get_path test passed: '//path
224+
do i = 1, 4
225+
select case (i)
226+
case(1); key = '/data/1/real'
227+
case(2); key = '/rfc6901 tests/ '
228+
case(3); key = '/rfc6901 tests/m~0n'
229+
case(4); key = '/rfc6901 tests/a~1b'
230+
end select
231+
call json%get(key,p)
232+
call core%get_path(p, path, found)
233+
if (found) then
234+
if (key==path) then
235+
write(error_unit,'(A)') 'get_path test passed: '//path
236+
else
237+
write(error_unit,'(A)') 'Error: path does not match: '//path//' '//key
238+
error_cnt = error_cnt + 1
239+
end if
229240
else
230-
write(error_unit,'(A)') 'Error: path does not match: '//path//' '//key
241+
write(error_unit,'(A)') 'Error: could not find '//key
231242
error_cnt = error_cnt + 1
232243
end if
233-
else
234-
write(error_unit,'(A)') 'Error: could not find '//key
235-
error_cnt = error_cnt + 1
236-
end if
244+
end do
237245

238246
! clean up
239247
write(error_unit,'(A)') ''

0 commit comments

Comments
 (0)