Skip to content

fix(config): support Chinese comma separator in allow_from environment variables#1301

Merged
yinwm merged 1 commit intosipeed:mainfrom
darrenzeng2025:fix/irc-comma-separator
Mar 11, 2026
Merged

fix(config): support Chinese comma separator in allow_from environment variables#1301
yinwm merged 1 commit intosipeed:mainfrom
darrenzeng2025:fix/irc-comma-separator

Conversation

@darrenzeng2025
Copy link
Contributor

📝 Description

This PR fixes an issue where IRC (and other channels) allow_from configuration fails when users accidentally use Chinese comma (,) instead of English comma (,) as separators in environment variables.

The fix adds an UnmarshalText method to FlexibleStringSlice that:

  • Handles comma-separated values from environment variables
  • Automatically converts Chinese commas (,) to English commas (,)
  • Trims whitespace from each value
  • Filters out empty strings

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)

🤖 AI Code Generation

  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)

🔗 Related Issue

Fixes #1280

📚 Technical Context

🧪 Test Environment

  • Hardware: x86_64 VM
  • OS: Linux 4.19.112
  • Go Version: 1.25.7 (required by project)

☑️ Checklist

  • My code follows the style of this project.
  • I have performed a self-review of my changes.
  • The change is minimal and focused on the specific issue.
  • Comments added for complex logic.

@CLAassistant
Copy link

CLAassistant commented Mar 10, 2026

CLA assistant check
All committers have signed the CLA.

@sipeed-bot sipeed-bot bot added type: bug Something isn't working domain: config go Pull requests that update go code labels Mar 10, 2026
Copy link

@nikolasdehor nikolasdehor left a comment

Choose a reason for hiding this comment

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

The intent is good -- supporting Chinese comma () as a separator in environment variables is a nice UX improvement for Chinese-speaking users who may accidentally use their IME's comma.

However, a few concerns:

  1. No tests -- this is a parsing change that affects allow_from, a security-sensitive configuration field. Unit tests for UnmarshalText are essential. Test cases should cover:

    • English commas only: "123,456,789"
    • Chinese commas only: "123,456,789"
    • Mixed: "123,456,789"
    • Trailing/leading commas: ",123,,456,"
    • Single value (no commas)
    • Empty string
    • Whitespace: " 123 , 456 "
  2. Scope creep risk -- should this also handle Japanese comma (), full-width comma (\uff0c which is the same as ), or semicolons? The current implementation is focused and reasonable, but consider documenting the supported separators.

  3. Interaction with JSON unmarshaling -- the existing UnmarshalJSON handles JSON arrays and numbers. The new UnmarshalText is only used by the env library for environment variable parsing. This separation is correct, but please verify that the env library calls UnmarshalText and not UnmarshalJSON when reading from environment variables.

  4. Make result nil vs empty slice consistent -- when text is empty, you return nil. When text is all commas (",,,"), the result would be an empty []string{} (allocated but empty). Consider whether nil vs empty-slice matters downstream.

Please add tests and this will be ready to approve.

@darrenzeng2025
Copy link
Contributor Author

@nicklein I've added comprehensive unit tests for the "FlexibleStringSlice.UnmarshalText" method as requested.

Tests added in "pkg/config/config_test.go":

  1. TestFlexibleStringSlice_UnmarshalText - Main test covering:

    • English commas only: "123,456,789"
    • Chinese commas only: "123,456,789"
    • Mixed English and Chinese commas: "123,456,789"
    • Single value: "123"
    • Values with whitespace trimming
    • Empty string (returns nil)
    • Only commas - returns empty slice
    • Mixed commas with empty parts
    • Complex values like email addresses
  2. TestFlexibleStringSlice_UnmarshalText_EmptySliceConsistency - Tests the distinction between:

    • Empty string → returns nil
    • Commas only → returns empty slice (not nil)

All tests have been verified to pass. The PR should now be ready for review and merge.

Note: There may still be conflicts in docker-compose.yml that need to be resolved via rebase if the base branch has changed.

@darrenzeng2025 darrenzeng2025 force-pushed the fix/irc-comma-separator branch from f98d3ee to 18728b4 Compare March 11, 2026 02:04
@darrenzeng2025
Copy link
Contributor Author

Update: Conflicts resolved!

The docker-compose.yml conflict has been resolved by rebasing onto the latest upstream/main. The PR now includes both:

  • The upstream "picoclaw-launcher" service
  • Our "picoclaw-gateway-dev" service (with dev profile)

The PR should now be mergeable. Please review when you have a chance.

…t variables

Add UnmarshalText method to FlexibleStringSlice to support both English
(,) and Chinese (,) comma separators in environment variables.

Includes comprehensive unit tests covering:
- English commas, Chinese commas, mixed commas
- Single values, whitespace trimming
- Empty strings, edge cases

Fixes sipeed#1280
@darrenzeng2025 darrenzeng2025 force-pushed the fix/irc-comma-separator branch from 18728b4 to 82756fa Compare March 11, 2026 02:06
@darrenzeng2025
Copy link
Contributor Author

分支已清理!

已移除与 PR #1301 无关的文件修改(Dockerfile.dev 和 docker-compose.yml 的更改)。

现在 PR 只包含以下修改:

  • "pkg/config/config.go" - 中文逗号分隔符的 UnmarshalText 实现
  • "pkg/config/config_test.go" - 全面的单元测试

PR 现在干净整洁,只关注解决中文逗号分隔符的问题。

Copy link
Collaborator

@yinwm yinwm left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR correctly fixes a real user pain point for CJK users who accidentally use Chinese commas in environment variables. The implementation is clean and well-tested.

✅ What's Good

  • Correctly implements encoding.TextUnmarshaler interface
  • Comprehensive test coverage (English/Chinese/mixed commas, whitespace, edge cases)
  • Clear comments explaining the purpose
  • Backward compatible

💡 Suggestions for Future Improvement

  1. nil vs empty slice inconsistency: Empty string returns nil, but comma-only input returns []string{}. Consider unifying the behavior.

  2. JSON config support: UnmarshalText only handles environment variables. If users configure via JSON file or Web UI with Chinese commas, UnmarshalJSON won't handle it. Consider adding similar support there if needed.

  3. Integration test: Consider adding a test that verifies the env library correctly parses PICOCLAW_CHANNELS_IRC_ALLOW_FROM="123,456".

These are minor suggestions and do not block merging. Thanks for the fix!

@yinwm yinwm merged commit 8431fa3 into sipeed:main Mar 11, 2026
4 checks passed
Alix-007 pushed a commit to Alix-007/picoclaw that referenced this pull request Mar 12, 2026
…t variables (sipeed#1301)

Add UnmarshalText method to FlexibleStringSlice to support both English
(,) and Chinese (,) comma separators in environment variables.

Includes comprehensive unit tests covering:
- English commas, Chinese commas, mixed commas
- Single values, whitespace trimming
- Empty strings, edge cases

Fixes sipeed#1280
dj-oyu pushed a commit to dj-oyu/picoclaw that referenced this pull request Mar 14, 2026
…t variables (sipeed#1301)

Add UnmarshalText method to FlexibleStringSlice to support both English
(,) and Chinese (,) comma separators in environment variables.

Includes comprehensive unit tests covering:
- English commas, Chinese commas, mixed commas
- Single values, whitespace trimming
- Empty strings, edge cases

Fixes sipeed#1280
dj-oyu pushed a commit to dj-oyu/picoclaw that referenced this pull request Mar 16, 2026
…t variables (sipeed#1301)

Add UnmarshalText method to FlexibleStringSlice to support both English
(,) and Chinese (,) comma separators in environment variables.

Includes comprehensive unit tests covering:
- English commas, Chinese commas, mixed commas
- Single values, whitespace trimming
- Empty strings, edge cases

Fixes sipeed#1280
j0904 pushed a commit to j0904/picoclaw that referenced this pull request Mar 22, 2026
…t variables (sipeed#1301)

Add UnmarshalText method to FlexibleStringSlice to support both English
(,) and Chinese (,) comma separators in environment variables.

Includes comprehensive unit tests covering:
- English commas, Chinese commas, mixed commas
- Single values, whitespace trimming
- Empty strings, edge cases

Fixes sipeed#1280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: config go Pull requests that update go code type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] About IRC -Allow From

4 participants