Skip to content

Commit b752a75

Browse files
authored
Merge pull request #39 from network-tools/feat-xpath-search
parse tree bug fix
2 parents 1e17754 + 9476cb1 commit b752a75

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.1.1] - 2026-01-01
9+
10+
### Fixed
11+
- 🐛 **Parser tree conversion** - Fixed TypeError in `_tree_to_yaml_structure` method
12+
- Added proper handling for path navigation conflicts when a key exists as non-dict value
13+
- Added conflict resolution for identifier assignment when overwriting existing values
14+
- Improved robustness when processing configuration files with conflicting key structures
15+
816
## [3.1.0] - 2025-12-28
917

1018
### 🎉 Format System Refinement

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "shconfparser"
7-
version = "3.1.0"
7+
version = "3.1.1"
88
description = "Network configuration parser that translates show command outputs into structured data"
99
readme = "README.md"
1010
requires-python = ">=3.9"

shconfparser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from .tree_parser import TreeParser
4242
from .xpath import XPath
4343

44-
__version__ = "3.1.0"
44+
__version__ = "3.1.1"
4545
__author__ = "Kiran Kumar Kotari"
4646
__email__ = "kirankotari@live.com"
4747

shconfparser/parser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,17 @@ def _tree_to_yaml_structure(self, tree: TreeData) -> Dict[str, Any]:
349349
for part in path_parts:
350350
if part not in current:
351351
current[part] = {}
352+
elif not isinstance(current[part], dict):
353+
# Key exists as non-dict, convert to dict
354+
current[part] = {}
352355
current = current[part]
353356

354357
# Add the identifier with its nested value
358+
# Check if identifier already exists and handle conflicts
359+
if identifier in current and not isinstance(current[identifier], dict):
360+
# Identifier exists as non-dict, we'll overwrite it
361+
# This handles cases where a leaf value conflicts with a container
362+
pass
355363
current[identifier] = self._tree_to_yaml_structure(value)
356364

357365
else:
@@ -360,6 +368,7 @@ def _tree_to_yaml_structure(self, tree: TreeData) -> Dict[str, Any]:
360368
# Two words: first is key, second is value
361369
# "hostname R1" → hostname: R1
362370
# "duplex auto" → duplex: auto
371+
# Overwrite any existing value (dict or otherwise)
363372
result[parts[0]] = parts[1]
364373

365374
elif len(parts) > 2:

0 commit comments

Comments
 (0)