Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bitssh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def get_config_content():
filtered_content = "\n".join(filtered_lines)

# Case-insensitive patterns - make sure all are properly case-insensitive
host_pattern = re.compile(r"^Host\s+(\w+)", re.MULTILINE | re.IGNORECASE)
# Fixed: Use \S+ instead of \w+ to match non-whitespace characters (includes hyphens, dots, etc.)
host_pattern = re.compile(r"^Host\s+(\S+)", re.MULTILINE | re.IGNORECASE)
hostname_pattern = re.compile(
r"^\s*(?:HostName|Hostname)\s+(\S+)", re.MULTILINE | re.IGNORECASE
)
Expand Down Expand Up @@ -84,4 +85,3 @@ def get_config_file_row_data():

def get_config_file_host_data() -> List[str]:
return [f"🖥️ -> {row[1]}" for row in get_config_file_row_data()]
return [f"🖥️ -> {row[1]}" for row in get_config_file_row_data()]
16 changes: 11 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,17 @@ def test_config_with_wildcards(self, mock_exists) -> None:
with patch("builtins.open", mock_open(read_data=wildcard_config)):
result = get_config_content()

# Behavior depends on regex pattern - \w+ might not match wildcards
# Adjust expectations based on actual implementation
self.assertIn("specific", result)
if "specific" in result:
self.assertEqual(result["specific"]["User"], "specific_user")
# Check for the actual key names that should be parsed
self.assertIn("*.example.com", result)
self.assertIn("specific.example.com", result) # Fixed: use full hostname
self.assertIn("*", result)

# Verify the parsed values
self.assertEqual(result["*.example.com"]["User"], "wildcard_user")
self.assertEqual(result["*.example.com"]["Port"], "3030")
self.assertEqual(result["specific.example.com"]["User"], "specific_user")
self.assertEqual(result["specific.example.com"]["Port"], "4040")
self.assertEqual(result["*"]["User"], "default_user")

@patch("os.path.exists", return_value=True)
def test_large_config_performance(self, mock_exists) -> None:
Expand Down