Kirill Simonov avatar Kirill Simonov committed 0db4612

Fix the bug when the `path` in `add_path_resolver` contains boolean values. Fix #43 (thanks to jstroud(at)mbi.ucla.edu for reporting and pointing to the cause).

Comments (0)

Files changed (1)

lib/yaml/resolver.py

     add_implicit_resolver = classmethod(add_implicit_resolver)
 
     def add_path_resolver(cls, tag, path, kind=None):
+        # Note: `add_path_resolver` is experimental.  The API could be changed.
+        # `new_path` is a pattern that is matched against the path from the
+        # root to the node that is being considered.  `node_path` elements are
+        # tuples `(node_check, index_check)`.  `node_check` is a node class:
+        # `ScalarNode`, `SequenceNode`, `MappingNode` or `None`.  `None`
+        # matches any kind of a node.  `index_check` could be `None`, a boolean
+        # value, a string value, or a number.  `None` and `False` match against
+        # any _value_ of sequence and mapping nodes.  `True` matches against
+        # any _key_ of a mapping node.  A string `index_check` matches against
+        # a mapping value that corresponds to a scalar key which content is
+        # equal to the `index_check` value.  An integer `index_check` matches
+        # against a sequence value with the index equal to `index_check`.
         if not 'yaml_path_resolvers' in cls.__dict__:
             cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy()
         new_path = []
                 return
         if index_check is True and current_index is not None:
             return
-        if index_check in [False, None] and current_index is None:
+        if (index_check is False or index_check is None)    \
+                and current_index is None:
             return
         if isinstance(index_check, basestring):
             if not (isinstance(current_index, ScalarNode)
                     and index_check == current_index.value):
                 return
-        elif isinstance(index_check, int):
+        elif isinstance(index_check, int) and not isinstance(index_check, bool):
             if index_check != current_index:
                 return
         return True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.