Skip to content

ALLOW_EMPTY_STRING_KEYS doesn't work when skip=True #73

Description

@danielpops

A code path exists (dpath.util.get) wherein ALLOW_EMPTY_STRING_KEYS ultimately interacts poorly with skip=True in the dpath.path.paths function.

Repro:

>>> import dpath.util
>>> import dpath.options
>>> dpath.options.ALLOW_EMPTY_STRING_KEYS=True
>>> d = {"": "", "Empty": { "": "value", "key": ""}}
>>> dpath.util.get(d, 'foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nail/home/dpopes/venv/local/lib/python2.7/site-packages/dpath/util.py", line 103, in get
    for item in search(obj, glob, yielded=True, separator=separator):
  File "/nail/home/dpopes/venv/local/lib/python2.7/site-packages/dpath/util.py", line 144, in _search_yielded
    for path in _inner_search(obj, globlist, separator, dirs=dirs):
  File "/nail/home/dpopes/venv/local/lib/python2.7/site-packages/dpath/util.py", line 159, in _inner_search
    for path in dpath.path.paths(obj, dirs, leaves, skip=True):
  File "/nail/home/dpopes/venv/local/lib/python2.7/site-packages/dpath/path.py", line 90, in paths
    elif (skip and k[0] == '+'):
IndexError: string index out of range

Similarly, at the source:

>>> import dpath.path
>>> import dpath.options
>>> dpath.options.ALLOW_EMPTY_STRING_KEYS=True
>>> d = {"": "", "Empty": { "": "value", "key": ""}}
>>> list(dpath.path.paths(d, skip=True))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nail/home/dpopes/venv/local/lib/python2.7/site-packages/dpath/path.py", line 90, in paths
    elif (skip and k[0] == '+'):
IndexError: string index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions