Skip to content

Fix URI encoding to preserve RFC 3986 unreserved characters in Aliyun signature#12

Merged
daflyinbed merged 6 commits intoaliyunfrom
copilot/fix-canonicalization-encoding-again
Jan 18, 2026
Merged

Fix URI encoding to preserve RFC 3986 unreserved characters in Aliyun signature#12
daflyinbed merged 6 commits intoaliyunfrom
copilot/fix-canonicalization-encoding-again

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

The Aliyun signature module was incorrectly percent-encoding RFC 3986 unreserved characters (-, _, ., ~) in URI paths and query strings, causing signature mismatches with the Aliyun API.

Changes

  • Created UNRESERVED encoding set by removing unreserved characters from NON_ALPHANUMERIC per RFC 3986
  • Updated canonicalize_uri() to preserve -_.~ in path segments
  • Updated build_canonical_query_string() to preserve -_.~ in query keys and values
  • Added tests validating unreserved character preservation and path separator handling

Example

Before:

// Using NON_ALPHANUMERIC encoded everything except alphanumerics
"key-1""key%2D1"
"value_2""value%5F2"  
"/path.with~chars""/path%2Ewith%7Echars"

After:

// Using UNRESERVED preserves RFC 3986 unreserved characters
"key-1""key-1"
"value_2""value_2"
"/path.with~chars""/path.with~chars"

Implementation

The UNRESERVED encoding set is created by removing the four unreserved punctuation marks from NON_ALPHANUMERIC:

const UNRESERVED: &AsciiSet = &NON_ALPHANUMERIC
    .remove(b'-')
    .remove(b'_')
    .remove(b'.')
    .remove(b'~');

Path separators (/) are preserved by splitting before encoding segments.

Original prompt

https://github.com/daflyinbed/janus/blob/aliyun/src/aliyun/signature.rs 里面 canonicalize_uri和build_canonical_query_string里面序列化的时候 字符-、_、.、~也不应该编码


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 17, 2026 16:58
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
…er explanations

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix encoding issues in canonicalization functions Fix URI encoding to preserve RFC 3986 unreserved characters in Aliyun signature Jan 17, 2026
Copilot AI requested a review from daflyinbed January 17, 2026 17:04
@daflyinbed
Copy link
Collaborator

@copilot 不对 直接在NON_ALPHANUMERIC上add我提到的几个要无视的字符

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 18, 2026

@copilot 不对 直接在NON_ALPHANUMERIC上add我提到的几个要无视的字符

Done! Changed to use NON_ALPHANUMERIC.remove() for -, _, ., ~ characters in commit 8a14c91.

@daflyinbed daflyinbed marked this pull request as ready for review January 18, 2026 01:03
@daflyinbed daflyinbed merged commit 8f34473 into aliyun Jan 18, 2026
@daflyinbed daflyinbed deleted the copilot/fix-canonicalization-encoding-again branch January 19, 2026 06:17
daflyinbed added a commit that referenced this pull request Jan 19, 2026
…liyun signature (#12)

* Initial plan

* Fix URI encoding to preserve unreserved characters (-, _, ., ~)

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

* Improve documentation comment for FRAGMENT encoding set

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

* Add test case for path separator preservation in URI canonicalization

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

* Enhance documentation for FRAGMENT encoding set with detailed character explanations

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

* Use NON_ALPHANUMERIC.remove() to exclude unreserved characters

Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: daflyinbed <21363956+daflyinbed@users.noreply.github.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.

2 participants