Skip to content

fix: allow non-ASCII characters in SSH host aliases#3154

Open
majiayu000 wants to merge 2 commits intowavetermdev:mainfrom
majiayu000:fix/issue-2937-ssh-non-ascii-host
Open

fix: allow non-ASCII characters in SSH host aliases#3154
majiayu000 wants to merge 2 commits intowavetermdev:mainfrom
majiayu000:fix/issue-2937-ssh-non-ascii-host

Conversation

@majiayu000
Copy link
Copy Markdown
Contributor

Fixes #2937

userHostRe in pkg/remote/connutil.go only matched [a-zA-Z0-9] for the host portion, so SSH Host aliases with Chinese (or other non-ASCII) characters failed validation.

Added \p{L} and \p{N} Unicode classes to the regexp so it accepts Unicode letters and digits in both host and user parts. Go's regexp package supports these natively.

Tests added in pkg/remote/connutil_test.go covering Chinese, Japanese, mixed, and ASCII-only inputs.

The userHostRe regexp only accepted ASCII letters and digits in the
host portion, rejecting valid SSH config Host aliases that contain
Chinese or other Unicode characters (e.g. "PROD-服务器"). Widen the
character classes with \p{L} and \p{N} to accept Unicode letters
and digits.

Fixes wavetermdev#2937

Signed-off-by: majiayu000 <1835304752@qq.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7d234bc3-80e7-449f-9304-64bbf841373c

📥 Commits

Reviewing files that changed from the base of the PR and between e1b6080 and ac25dd3.

📒 Files selected for processing (1)
  • pkg/remote/connutil_test.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/remote/connutil_test.go

Walkthrough

This pull request updates the userHostRe regular expression in pkg/remote/connutil.go to accept Unicode letters and digits (via \p{L} and \p{N}) in both the username and host components. Accompanying this change, a new test file pkg/remote/connutil_test.go is introduced with a table-driven test suite that validates the ParseOpts function across various input scenarios, including standard connection strings, Unicode hostnames, and invalid inputs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: allowing non-ASCII characters in SSH host aliases through regex updates.
Description check ✅ Passed The description is clearly related to the changeset, explaining the regex fix, Unicode class additions, and test coverage for non-ASCII SSH host aliases.
Linked Issues check ✅ Passed The PR fully addresses the requirements in issue #2937 by updating the regex to accept Unicode letters and digits, enabling proper parsing of non-ASCII SSH host aliases.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the SSH host alias parsing issue; the regex update and corresponding tests are within the scope of the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@majiayu000 majiayu000 marked this pull request as ready for review March 30, 2026 14:13
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Mar 30, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • pkg/remote/connutil_test.go - Added unicode username test case

The new test case 用户@服务器:22 (Chinese characters for user and server) correctly tests unicode username handling, building on the previous fix that added Unicode character class support (\p{L} and \p{N}) to the regex pattern.


Reviewed by minimax-m2.5 · incremental review from e1b6080


Reviewed by minimax-m2.5-20260211 · 196,102 tokens

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/remote/connutil_test.go (1)

19-24: Add one Unicode-username test case for full parser coverage.

Current tests validate Unicode host aliases well; adding a Unicode user@host case would lock in the expanded username behavior too.

Suggested test additions
 func TestParseOpts(t *testing.T) {
 	tests := []struct {
@@
 		{"mixed ascii and chinese with user and port", "user@PROD-阿里云:22", "user", "PROD-阿里云", "22", false},
+		{"unicode user and host", "用户@服务器:22", "用户", "服务器", "22", false},
 		{"unicode only host", "服务器", "", "服务器", "", false},
 		{"japanese host", "サーバー", "", "サーバー", "", false},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/remote/connutil_test.go` around lines 19 - 24, Add a test row to the test
table in pkg/remote/connutil_test.go that covers a Unicode username (e.g., an
entry with address like "用户@服务器"), expecting parsed user "用户", host "服务器", empty
port and success=false as appropriate for other cases; update the same table
used by the test that asserts parsed user/host/port (the table of cases in
connutil_test.go) so the existing parser/assertion logic picks up and validates
the Unicode username parsing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/remote/connutil_test.go`:
- Around line 19-24: Add a test row to the test table in
pkg/remote/connutil_test.go that covers a Unicode username (e.g., an entry with
address like "用户@服务器"), expecting parsed user "用户", host "服务器", empty port and
success=false as appropriate for other cases; update the same table used by the
test that asserts parsed user/host/port (the table of cases in connutil_test.go)
so the existing parser/assertion logic picks up and validates the Unicode
username parsing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 804103c7-2c09-44d2-8bb8-21b20f6a2b3d

📥 Commits

Reviewing files that changed from the base of the PR and between 96c2526 and e1b6080.

📒 Files selected for processing (2)
  • pkg/remote/connutil.go
  • pkg/remote/connutil_test.go

Signed-off-by: majiayu000 <1835304752@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SSH connection and connections.json mapping fail when Host alias contains non-ASCII (Chinese) character

1 participant